home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / config / tc-m68k.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-27  |  117.8 KB  |  5,265 lines

  1. /* tc-m68k.c  All the m68020 specific stuff in one convenient, huge,
  2.    slow to compile, easy to find file.
  3.  
  4.    Copyright (C) 1987, 1991, 1992, 1993 Free Software Foundation, Inc.
  5.  
  6.    This file is part of GAS, the GNU Assembler.
  7.  
  8.    GAS is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2, or (at your option)
  11.    any later version.
  12.  
  13.    GAS is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with GAS; see the file COPYING.  If not, write to
  20.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include <ctype.h>
  23. #define  NO_RELOC 0
  24. #include "as.h"
  25.  
  26. /* need TARGET_CPU */
  27. #include "config.h"
  28.  
  29. #include "obstack.h"
  30.  
  31. /* The opcode table is too big for gcc, which (currently) requires
  32.    exponential space at compile time for initialized arrays.  */
  33. #ifdef __GNUC__
  34. #define DO_BREAK_UP_BIG_DECL
  35. #define BREAK_UP_BIG_DECL    }; struct m68k_opcode m68k_opcodes_2[] = {
  36. #define AND_OTHER_PART        sizeof (m68k_opcodes_2)
  37. #endif
  38.  
  39. /* Note that this file includes real declarations and thus can only be
  40.    included by one source file per executable.  */
  41. #include "opcode/m68k.h"
  42.  
  43. /* This array holds the chars that always start a comment.  If the
  44.    pre-processor is disabled, these aren't very useful */
  45. CONST char comment_chars[] = "|";
  46.  
  47. /* This array holds the chars that only start a comment at the beginning of
  48.    a line.  If the line seems to have the form '# 123 filename'
  49.    .line and .file directives will appear in the pre-processed output */
  50. /* Note that input_file.c hand checks for '#' at the beginning of the
  51.    first line of the input file.  This is because the compiler outputs
  52.    #NO_APP at the beginning of its output. */
  53. /* Also note that comments like this one will always work. */
  54. CONST char line_comment_chars[] = "#";
  55.  
  56. CONST char line_separator_chars[] = "";
  57.  
  58. /* Chars that can be used to separate mant from exp in floating point nums */
  59. CONST char EXP_CHARS[] = "eE";
  60.  
  61. /* Chars that mean this number is a floating point constant, as
  62.    in "0f12.456" or "0d1.2345e12".  */
  63.  
  64. CONST char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  65.  
  66. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  67.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  68.    but nothing is ideal around here.  */
  69.  
  70. const int md_reloc_size = 8;    /* Size of relocation record */
  71.  
  72. /* Are we trying to generate PIC code?  If so, absolute references
  73.    ought to be made into linkage table references or pc-relative
  74.    references.  */
  75. int flag_want_pic;
  76.  
  77. static int flag_short_refs;    /* -l option */
  78. static int flag_long_jumps;    /* -S option */
  79.  
  80. #ifdef REGISTER_PREFIX_OPTIONAL
  81. int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
  82. #else
  83. int flag_reg_prefix_optional;
  84. #endif
  85.  
  86. /* Its an arbitrary name:  This means I don't approve of it */
  87. /* See flames below */
  88. static struct obstack robyn;
  89.  
  90. #define TAB(x,y)    (((x)<<2)+(y))
  91. #define TABTYPE(xy)     ((xy) >> 2)
  92. #define BYTE        0
  93. #define SHORT        1
  94. #define LONG        2
  95. #define SZ_UNDEF    3
  96. #undef BRANCH
  97. #define ABRANCH        1
  98. #define FBRANCH        2
  99. #define PCREL        3
  100. #define BCC68000        4
  101. #define DBCC            5
  102. #define PCLEA        6
  103.  
  104. struct m68k_incant
  105.   {
  106.     char *m_operands;
  107.     unsigned long m_opcode;
  108.     short m_opnum;
  109.     short m_codenum;
  110.     int m_arch;
  111.     struct m68k_incant *m_next;
  112.   };
  113.  
  114. #define getone(x)    ((((x)->m_opcode)>>16)&0xffff)
  115. #define gettwo(x)    (((x)->m_opcode)&0xffff)
  116.  
  117. /* Operands we can parse:  (And associated modes)
  118.  
  119.    numb:    8 bit num
  120.    numw:    16 bit num
  121.    numl:    32 bit num
  122.    dreg:    data reg 0-7
  123.    reg:    address or data register
  124.    areg:    address register
  125.    apc:    address register, PC, ZPC or empty string
  126.    num:    16 or 32 bit num
  127.    num2:    like num
  128.    sz:    w or l        if omitted, l assumed
  129.    scale:    1 2 4 or 8    if omitted, 1 assumed
  130.  
  131.    7.4 IMMED #num                --> NUM
  132.    0.? DREG  dreg                --> dreg
  133.    1.? AREG  areg                --> areg
  134.    2.? AINDR areg@                --> *(areg)
  135.    3.? AINC  areg@+            --> *(areg++)
  136.    4.? ADEC  areg@-            --> *(--areg)
  137.    5.? AOFF  apc@(numw)            --> *(apc+numw)    -- empty string and ZPC not allowed here
  138.    6.? AINDX apc@(num,reg:sz:scale)    --> *(apc+num+reg*scale)
  139.    6.? AINDX apc@(reg:sz:scale)        --> same, with num=0
  140.    6.? APODX apc@(num)@(num2,reg:sz:scale)    --> *(*(apc+num)+num2+reg*scale)
  141.    6.? APODX apc@(num)@(reg:sz:scale)    --> same, with num2=0
  142.    6.? AMIND apc@(num)@(num2)        --> *(*(apc+num)+num2) (previous mode without an index reg)
  143.    6.? APRDX apc@(num,reg:sz:scale)@(num2)    --> *(*(apc+num+reg*scale)+num2)
  144.    6.? APRDX apc@(reg:sz:scale)@(num2)    --> same, with num=0
  145.    7.0 ABSL  num:sz            --> *(num)
  146.    num                --> *(num) (sz L assumed)
  147.    *** MSCR  otherreg            --> Magic
  148.    With -l option
  149.    5.? AOFF  apc@(num)            --> *(apc+num) -- empty string and ZPC not allowed here still
  150.    ?.? DINDR dreg@            --> (dreg) -- cas2 only
  151.  
  152.    examples:
  153.    #foo    #0x35    #12
  154.    d2
  155.    a4
  156.    a3@
  157.    a5@+
  158.    a6@-
  159.    a2@(12)    pc@(14)
  160.    a1@(5,d2:w:1)    @(45,d6:l:4)
  161.    pc@(a2)        @(d4)
  162.    etc . . .
  163.  
  164.  
  165.    #name@(numw)    -->turn into PC rel mode
  166.    apc@(num8,reg:sz:scale)        --> *(apc+num8+reg*scale)
  167.  
  168.    */
  169.  
  170. enum operand_type
  171.   {
  172.     IMMED = 1,
  173.     DREG,
  174.     AREG,
  175.     AINDR,
  176.     ADEC,
  177.     AINC,
  178.     AOFF,
  179.     AINDX,
  180.     APODX,
  181.     AMIND,
  182.     APRDX,
  183.     ABSL,
  184.     MSCR,
  185.     REGLST,
  186.     DINDR
  187.   };
  188.  
  189.  
  190. struct m68k_exp
  191.   {
  192.     char *e_beg;
  193.     char *e_end;
  194.     segT e_seg;
  195.     expressionS e_exp;
  196.     short e_siz;        /* 0== default 1==short/byte 2==word 3==long */
  197.   };
  198.  
  199. /* DATA and ADDR have to be contiguous, so that reg-DATA gives
  200.    0-7==data reg, 8-15==addr reg for operands that take both types.
  201.  
  202.    We don't use forms like "ADDR0 = ADDR" here because this file is
  203.    likely to be used on an Apollo, and the broken Apollo compiler
  204.    gives an `undefined variable' error if we do that, according to
  205.    troy@cbme.unsw.edu.au.  */
  206.  
  207. #define DATA DATA0
  208. #define ADDR ADDR0
  209. #define SP ADDR7
  210. #define FPREG FP0
  211. #define COPNUM  COP0
  212. #define BAD BAD0
  213. #define BAC BAC0
  214.  
  215. enum _register
  216.   {
  217.     DATA0 = 1,            /*   1- 8 == data registers 0-7 */
  218.     DATA1,
  219.     DATA2,
  220.     DATA3,
  221.     DATA4,
  222.     DATA5,
  223.     DATA6,
  224.     DATA7,
  225.  
  226.     ADDR0,
  227.     ADDR1,
  228.     ADDR2,
  229.     ADDR3,
  230.     ADDR4,
  231.     ADDR5,
  232.     ADDR6,
  233.     ADDR7,
  234.  
  235.     /* Note that COP0==processor #1 -- COP0+7==#8, which stores as 000 */
  236.     /* I think. . .  */
  237.  
  238.     FP0,            /* Eight FP registers */
  239.     FP1,
  240.     FP2,
  241.     FP3,
  242.     FP4,
  243.     FP5,
  244.     FP6,
  245.     FP7,
  246.  
  247.     COP0,            /* Co-processor #1-#8 */
  248.     COP1,
  249.     COP2,
  250.     COP3,
  251.     COP4,
  252.     COP5,
  253.     COP6,
  254.     COP7,
  255.  
  256.     PC,                /* Program counter */
  257.     ZPC,            /* Hack for Program space, but 0 addressing */
  258.     SR,                /* Status Reg */
  259.     CCR,            /* Condition code Reg */
  260.  
  261.     /* These have to be grouped together for the movec instruction to work. */
  262.     USP,            /*  User Stack Pointer */
  263.     ISP,            /*  Interrupt stack pointer */
  264.     SFC,
  265.     DFC,
  266.     CACR,
  267.     VBR,
  268.     CAAR,
  269.     MSP,
  270.     ITT0,
  271.     ITT1,
  272.     DTT0,
  273.     DTT1,
  274.     MMUSR,
  275.     TC,
  276.     SRP,
  277.     URP,
  278.     BUSCR,            /* 68060 added these */
  279.     PCR,
  280. #define last_movec_reg PCR
  281.     /* end of movec ordering constraints */
  282.  
  283.     FPI,
  284.     FPS,
  285.     FPC,
  286.  
  287.     DRP,            /* 68851 or 68030 MMU regs */
  288.     CRP,
  289.     CAL,
  290.     VAL,
  291.     SCC,
  292.     AC,
  293.     BAD0,
  294.     BAD1,
  295.     BAD2,
  296.     BAD3,
  297.     BAD4,
  298.     BAD5,
  299.     BAD6,
  300.     BAD7,
  301.     BAC0,
  302.     BAC1,
  303.     BAC2,
  304.     BAC3,
  305.     BAC4,
  306.     BAC5,
  307.     BAC6,
  308.     BAC7,
  309.     PSR,            /* aka MMUSR on 68030 (but not MMUSR on 68040)
  310.                    and ACUSR on 68ec030 */
  311.     PCSR,
  312.  
  313.     IC,                /* instruction cache token */
  314.     DC,                /* data cache token */
  315.     NC,                /* no cache token */
  316.     BC,                /* both caches token */
  317.  
  318.     TT0,            /* 68030 access control unit regs */
  319.     TT1,
  320.   };
  321.  
  322. static const enum _register m68000_control_regs[] = { 0 };
  323. static const enum _register m68010_control_regs[] = {
  324.   SFC, DFC, USP, VBR,
  325.   0
  326. };
  327. static const enum _register m68020_control_regs[] = {
  328.   SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
  329.   0
  330. };
  331. static const enum _register m68040_control_regs[] = {
  332.   SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
  333.   USP, VBR, MSP, ISP, MMUSR, URP, SRP,
  334.   0
  335. };
  336. static const enum _register m68060_control_regs[] = {
  337.   SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
  338.   USP, VBR, URP, SRP, PCR,
  339.   0
  340. };
  341.  
  342. static const enum _register *control_regs;
  343.  
  344. /* Internal form of an operand.  */
  345. struct m68k_op
  346.   {
  347.     char *error;        /* Couldn't parse it */
  348.     enum operand_type mode;    /* What mode this instruction is in.  */
  349.     enum _register reg;        /* Base register */
  350.     struct m68k_exp *con1;
  351.     int ireg;            /* Index register */
  352.     int isiz;            /* 0==unspec  1==byte(?)  2==short  3==long  */
  353.     int imul;            /* Multipy ireg by this (1,2,4,or 8) */
  354.     struct m68k_exp *con2;
  355.   };
  356.  
  357. /* internal form of a 68020 instruction */
  358. struct m68k_it
  359.   {
  360.     char *error;
  361.     char *args;            /* list of opcode info */
  362.     int numargs;
  363.  
  364.     int numo;            /* Number of shorts in opcode */
  365.     short opcode[11];
  366.  
  367.     struct m68k_op operands[6];
  368.  
  369.     int nexp;            /* number of exprs in use */
  370.     struct m68k_exp exprs[4];
  371.  
  372.     int nfrag;            /* Number of frags we have to produce */
  373.     struct
  374.       {
  375.     int fragoff;        /* Where in the current opcode[] the frag ends */
  376.     symbolS *fadd;
  377.     long foff;
  378.     int fragty;
  379.       }
  380.     fragb[4];
  381.  
  382.     int nrel;            /* Num of reloc strucs in use */
  383.     struct
  384.       {
  385.     int n;
  386.     expressionS exp;
  387.     char wid;
  388.     char pcrel;
  389.       }
  390.     reloc[5];            /* Five is enough??? */
  391.   };
  392.  
  393. #define cpu_of_arch(x)        ((x) & m68000up)
  394. #define float_of_arch(x)    ((x) & mfloat)
  395. #define mmu_of_arch(x)        ((x) & mmmu)
  396.  
  397. static struct m68k_it the_ins;    /* the instruction being assembled */
  398.  
  399. #define seg(exp)    ((exp)->e_seg)
  400. #define op(exp)        ((exp)->e_exp.X_op)
  401. #define adds(exp)    ((exp)->e_exp.X_add_symbol)
  402. #define subs(exp)    ((exp)->e_exp.X_op_symbol)
  403. #define offs(exp)    ((exp)->e_exp.X_add_number)
  404.  
  405. /* Macros for adding things to the m68k_it struct */
  406.  
  407. #define addword(w)    the_ins.opcode[the_ins.numo++]=(w)
  408.  
  409. /* Like addword, but goes BEFORE general operands */
  410. static void
  411. insop (w, opcode)
  412.      int w;
  413.      struct m68k_incant *opcode;
  414. {
  415.   int z;
  416.   for(z=the_ins.numo;z>opcode->m_codenum;--z)
  417.     the_ins.opcode[z]=the_ins.opcode[z-1];
  418.   for(z=0;z<the_ins.nrel;z++)
  419.     the_ins.reloc[z].n+=2;
  420.   the_ins.opcode[opcode->m_codenum]=w;
  421.   the_ins.numo++;
  422. }
  423.  
  424. static struct m68k_exp *
  425. add_exp (beg, end)
  426.      char *beg;
  427.      char *end;
  428. {
  429.   the_ins.exprs[the_ins.nexp].e_beg=beg;
  430.   the_ins.exprs[the_ins.nexp].e_end=end;
  431.   return &the_ins.exprs[the_ins.nexp++];
  432. }
  433.  
  434.  
  435. /* The numo+1 kludge is so we can hit the low order byte of the prev word.
  436.    Blecch.  */
  437. static void
  438. add_fix (width, exp, pc_rel)
  439.      char width;
  440.      struct m68k_exp *exp;
  441.      int pc_rel;
  442. {
  443.   the_ins.reloc[the_ins.nrel].n = (((width)=='B')
  444.                    ? (the_ins.numo*2-1)
  445.                    : (((width)=='b')
  446.                       ? ((the_ins.numo-1)*2)
  447.                       : (the_ins.numo*2)));
  448.   the_ins.reloc[the_ins.nrel].exp = exp->e_exp;
  449.   the_ins.reloc[the_ins.nrel].wid = width;
  450.   the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
  451. }
  452.  
  453. static void
  454. add_frag(add,off,type)
  455.      symbolS *add;
  456.      long off;
  457.      int type;
  458. {
  459.   the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;
  460.   the_ins.fragb[the_ins.nfrag].fadd=add;
  461.   the_ins.fragb[the_ins.nfrag].foff=off;
  462.   the_ins.fragb[the_ins.nfrag++].fragty=type;
  463. }
  464.  
  465. #define isvar(exp) \
  466.   ((exp) && op (exp) != O_constant && op (exp) != O_big)
  467.  
  468. static char *crack_operand PARAMS ((char *str, struct m68k_op *opP));
  469. static int get_num PARAMS ((struct m68k_exp *exp, int ok));
  470. static int get_regs PARAMS ((int i, char *str, struct m68k_op *opP));
  471. static int reverse_16_bits PARAMS ((int in));
  472. static int reverse_8_bits PARAMS ((int in));
  473. static int try_index PARAMS ((char **s, struct m68k_op *opP));
  474. static void install_gen_operand PARAMS ((int mode, int val));
  475. static void install_operand PARAMS ((int mode, int val));
  476. static void s_bss PARAMS ((int));
  477. static void s_data1 PARAMS ((int));
  478. static void s_data2 PARAMS ((int));
  479. static void s_even PARAMS ((int));
  480. static void s_proc PARAMS ((int));
  481.  
  482. static int current_architecture;
  483.  
  484. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  485.    on the 68000.  The 68000 doesn't support long branches with branchs */
  486.  
  487. /* This table desribes how you change sizes for the various types of variable
  488.    size expressions.  This version only supports two kinds. */
  489.  
  490. /* Note that calls to frag_var need to specify the maximum expansion
  491.    needed; this is currently 10 bytes for DBCC.  */
  492.  
  493. /* The fields are:
  494.    How far Forward this mode will reach:
  495.    How far Backward this mode will reach:
  496.    How many bytes this mode will add to the size of the frag
  497.    Which mode to go to if the offset won't fit in this one
  498.    */
  499. CONST relax_typeS md_relax_table[] =
  500. {
  501.   {1, 1, 0, 0},            /* First entries aren't used */
  502.   {1, 1, 0, 0},            /* For no good reason except */
  503.   {1, 1, 0, 0},            /* that the VAX doesn't either */
  504.   {1, 1, 0, 0},
  505.  
  506.   {(127), (-128), 0, TAB (ABRANCH, SHORT)},
  507.   {(32767), (-32768), 2, TAB (ABRANCH, LONG)},
  508.   {0, 0, 4, 0},
  509.   {1, 1, 0, 0},
  510.  
  511.   {1, 1, 0, 0},            /* FBRANCH doesn't come BYTE */
  512.   {(32767), (-32768), 2, TAB (FBRANCH, LONG)},
  513.   {0, 0, 4, 0},
  514.   {1, 1, 0, 0},
  515.  
  516.   {1, 1, 0, 0},            /* PCREL doesn't come BYTE */
  517.   {(32767), (-32768), 2, TAB (PCREL, LONG)},
  518.   {0, 0, 4, 0},
  519.   {1, 1, 0, 0},
  520.  
  521.   {(127), (-128), 0, TAB (BCC68000, SHORT)},
  522.   {(32767), (-32768), 2, TAB (BCC68000, LONG)},
  523.   {0, 0, 6, 0},            /* jmp long space */
  524.   {1, 1, 0, 0},
  525.  
  526.   {1, 1, 0, 0},            /* DBCC doesn't come BYTE */
  527.   {(32767), (-32768), 2, TAB (DBCC, LONG)},
  528.   {0, 0, 10, 0},        /* bra/jmp long space */
  529.   {1, 1, 0, 0},
  530.  
  531.   {1, 1, 0, 0},            /* PCLEA doesn't come BYTE */
  532.   {32767, -32768, 2, TAB (PCLEA, LONG)},
  533.   {0, 0, 6, 0},
  534.   {1, 1, 0, 0},
  535.  
  536. };
  537.  
  538. /* These are the machine dependent pseudo-ops.  These are included so
  539.    the assembler can work on the output from the SUN C compiler, which
  540.    generates these.
  541.    */
  542.  
  543. /* This table describes all the machine specific pseudo-ops the assembler
  544.    has to support.  The fields are:
  545.    pseudo-op name without dot
  546.    function to call to execute this pseudo-op
  547.    Integer arg to pass to the function
  548.    */
  549. CONST pseudo_typeS md_pseudo_table[] =
  550. {
  551.   {"data1", s_data1, 0},
  552.   {"data2", s_data2, 0},
  553.   {"bss", s_bss, 0},
  554.   {"even", s_even, 0},
  555.   {"skip", s_space, 0},
  556.   {"proc", s_proc, 0},
  557. #ifdef TE_SUN3
  558.   {"align", s_align_bytes, 0},
  559. #endif
  560.   {0, 0, 0}
  561. };
  562.  
  563.  
  564. /* The mote pseudo ops are put into the opcode table, since they
  565.    don't start with a . they look like opcodes to gas.
  566.    */
  567. extern void obj_coff_section ();
  568.  
  569. CONST pseudo_typeS mote_pseudo_table[] =
  570. {
  571.  
  572.   {"dc.l", cons, 4},
  573.   {"dc", cons, 2},
  574.   {"dc.w", cons, 2},
  575.   {"dc.b", cons, 1},
  576.  
  577.   {"ds.l", s_space, 4},
  578.   {"ds", s_space, 2},
  579.   {"ds.w", s_space, 2},
  580.   {"ds.b", s_space, 1},
  581.  
  582.   {"xdef", s_globl, 0},
  583.   {"align", s_align_ptwo, 0},
  584. #ifdef M68KCOFF
  585.   {"sect", obj_coff_section, 0},
  586.   {"section", obj_coff_section, 0},
  587. #endif
  588.   {0, 0, 0}
  589. };
  590.  
  591. #define issbyte(x)    ((x)>=-128 && (x)<=127)
  592. #define isubyte(x)    ((x)>=0 && (x)<=255)
  593. #define issword(x)    ((x)>=-32768 && (x)<=32767)
  594. #define isuword(x)    ((x)>=0 && (x)<=65535)
  595.  
  596. #define isbyte(x)    ((x)>= -255 && (x)<=255)
  597. #define isword(x)    ((x)>=-32768 && (x)<=65535)
  598. #define islong(x)    (1)
  599.  
  600. extern char *input_line_pointer;
  601.  
  602. enum
  603.   {
  604.     FAIL = 0,
  605.     OK = 1,
  606.   };
  607.  
  608. /* JF these tables here are for speed at the expense of size */
  609. /* You can replace them with the #if 0 versions if you really
  610.    need space and don't mind it running a bit slower */
  611.  
  612. static char mklower_table[256];
  613. #define mklower(c) (mklower_table[(unsigned char)(c)])
  614. static char notend_table[256];
  615. static char alt_notend_table[256];
  616. #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
  617.                                 alt_notend_table[(unsigned char)(s[1])])))
  618.  
  619. #if 0
  620. #define mklower(c)    (isupper(c) ? tolower(c) : c)
  621. #endif
  622.  
  623.  
  624. /* JF modified this to handle cases where the first part of a symbol name
  625.    looks like a register */
  626.  
  627. /*
  628.  * m68k_reg_parse() := if it looks like a register, return it's token &
  629.  * advance the pointer.
  630.  */
  631.  
  632. enum _register
  633. m68k_reg_parse (ccp)
  634.      register char **ccp;
  635. {
  636.   char *start = *ccp;
  637.   char c;
  638.   char *p;
  639.   symbolS *symbolP;
  640.  
  641.   if (flag_reg_prefix_optional)
  642.     {
  643.       if (*start == REGISTER_PREFIX)
  644.     start++;
  645.       p = start;
  646.     }
  647.   else
  648.     {
  649.       if (*start != REGISTER_PREFIX)
  650.     return FAIL;
  651.       p = start + 1;
  652.     }
  653.  
  654.   if (!isalpha (*p) || !is_name_beginner (*p))
  655.     return FAIL;
  656.  
  657.   c = *p++;
  658.   while (isalpha (c) || isdigit (c) || c == '_')
  659.     {
  660.       c = *p++;
  661.     }
  662.  
  663.   *--p = 0;
  664.   symbolP = symbol_find (start);
  665.   *p = c;
  666.  
  667.   if (symbolP && S_GET_SEGMENT (symbolP) == reg_section)
  668.     {
  669.       *ccp = p;
  670.       return S_GET_VALUE (symbolP);
  671.     }
  672.  
  673.   return FAIL;
  674. }
  675.  
  676. #define SKIP_WHITE()    { str++; if(*str==' ') str++;}
  677. #define SKIP_W()    { ss++; if(*ss==' ') ss++;}
  678.  
  679. /* Parse an index specification using Motorola syntax.  */
  680.  
  681. static int
  682. try_moto_index (s, opP)
  683.      char **s;
  684.      struct m68k_op *opP;
  685. {
  686.   register int i;
  687.   char *ss;
  688.  
  689.   ss = *s;
  690.   /* SKIP_W(); */
  691.   if (*ss == ' ')
  692.     ss++;
  693.   i = m68k_reg_parse (&ss);
  694.   if (!(i >= DATA + 0 && i <= ADDR + 7))
  695.     {                /* if i is not DATA or ADDR reg */
  696.       opP->error = "Invalid index register";
  697.       *s = ss;
  698.       return FAIL;
  699.     }
  700.   opP->ireg = i;
  701.   /* SKIP_W(); */
  702.   if (*ss == ')')
  703.     {
  704.       opP->isiz = 0;
  705.       opP->imul = 1;
  706.       SKIP_W ();
  707.       *s = ss;
  708.       return OK;
  709.     }
  710.   if (*ss != '.')
  711.     {
  712.       opP->error = "Missing . in index register";
  713.       *s = ss;
  714.       return FAIL;
  715.     }
  716.   SKIP_W ();
  717.   if (mklower (*ss) == 'w')
  718.     opP->isiz = 2;
  719.   else if (mklower (*ss) == 'l')
  720.     opP->isiz = 3;
  721.   else
  722.     {
  723.       opP->error = "Size spec not .W or .L";
  724.       *s = ss;
  725.       return FAIL;
  726.     }
  727.   SKIP_W ();
  728.   if (*ss == '.' || *ss == '*')
  729.     {
  730.       SKIP_W ();
  731.       switch (*ss)
  732.     {
  733.     case '1':
  734.     case '2':
  735.     case '4':
  736.     case '8':
  737.       opP->imul = *ss - '0';
  738.       break;
  739.     default:
  740.       opP->error = "index multiplier not 1, 2, 4 or 8";
  741.       *s = ss;
  742.       return FAIL;
  743.     }
  744.       SKIP_W ();
  745.     }
  746.   else
  747.     opP->imul = 1;
  748.   if (*ss != ')')
  749.     {
  750.       opP->error = "Missing )";
  751.       *s = ss;
  752.       return FAIL;
  753.     }
  754.   SKIP_W ();
  755.   *s = ss;
  756.   return OK;
  757. }
  758.  
  759. /*
  760.  *
  761.  * try_index := data_or_address_register + ')' + SKIP_W
  762.  *    | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
  763.  *
  764.  * multiplier := <empty>
  765.  *    | ':' + multiplier_number
  766.  *    ;
  767.  *
  768.  * multiplier_number := '1' | '2' | '4' | '8' ;
  769.  *
  770.  * size_spec := 'l' | 'L' | 'w' | 'W' ;
  771.  *
  772.  * SKIP_W := <empty> | ' ' ;
  773.  *
  774.  */
  775.  
  776. static int
  777. try_index (s, opP)
  778.      char **s;
  779.      struct m68k_op *opP;
  780. {
  781.   register int i;
  782.   char *ss;
  783.  
  784.   ss = *s;
  785.   /* SKIP_W(); */
  786.   i = m68k_reg_parse (&ss);
  787.   if (!(i >= DATA + 0 && i <= ADDR + 7))
  788.     {                /* if i is not DATA or ADDR reg */
  789.       *s = ss;
  790.       return FAIL;
  791.     }
  792.   opP->ireg = i;
  793.   /* SKIP_W(); */
  794.   if (*ss == ')')
  795.     {
  796.       opP->isiz = 0;
  797.       opP->imul = 1;
  798.       SKIP_W ();
  799.       *s = ss;
  800.       return OK;
  801.     }
  802.   if (*ss != ':')
  803.     {
  804.       opP->error = "Missing : in index register";
  805.       *s = ss;
  806.       return FAIL;
  807.     }
  808.   SKIP_W ();
  809.   switch (*ss)
  810.     {
  811.     case 'w':
  812.     case 'W':
  813.       opP->isiz = 2;
  814.       break;
  815.     case 'l':
  816.     case 'L':
  817.       opP->isiz = 3;
  818.       break;
  819.     default:
  820.       opP->error = "Index register size spec not :w or :l";
  821.       *s = ss;
  822.       return FAIL;
  823.     }
  824.   SKIP_W ();
  825.   if (*ss == ':')
  826.     {
  827.       SKIP_W ();
  828.       switch (*ss)
  829.     {
  830.     case '1':
  831.     case '2':
  832.     case '4':
  833.     case '8':
  834.       if (cpu_of_arch (current_architecture) < m68020)
  835.         {
  836.           opP->error = "no index scaling in pre-68020's";
  837.           *s = ss;
  838.           return FAIL;
  839.         }
  840.       opP->imul = *ss - '0';
  841.       break;
  842.     default:
  843.       opP->error = "index multiplier not 1, 2, 4 or 8";
  844.       *s = ss;
  845.       return FAIL;
  846.     }
  847.       SKIP_W ();
  848.     }
  849.   else
  850.     opP->imul = 1;
  851.   if (*ss != ')')
  852.     {
  853.       opP->error = "Missing )";
  854.       *s = ss;
  855.       return FAIL;
  856.     }
  857.   SKIP_W ();
  858.   *s = ss;
  859.   return OK;
  860. }                /* try_index() */
  861.  
  862. /* Ian Taylor expanded this function to accept both MIT and Motorola
  863.    syntax.  I removed the old comment, since it was wrong.  The syntax
  864.    this accepted even before my changes was complex and undocumented.
  865.    I mainly added a large case when the operand string does not
  866.    contain an '@', since the Motorola syntax does not use the '@'
  867.    character.  */
  868.  
  869. int
  870. m68k_ip_op (str, opP)
  871.      char *str;
  872.      register struct m68k_op *opP;
  873. {
  874.   char *strend;
  875.   long i;
  876.   char *parse_index ();
  877.   int needp;
  878.  
  879.   if (*str == ' ')
  880.     {
  881.       str++;
  882.     }                /* Find the beginning of the string */
  883.  
  884.   if (!*str)
  885.     {
  886.       opP->error = "Missing operand";
  887.       return FAIL;
  888.     }                /* Out of gas */
  889.  
  890.   for (strend = str; *strend; strend++)
  891.     ;
  892.   --strend;
  893.  
  894.   if (*str == '#' || *str == '&')
  895.     {
  896.       str++;
  897.       opP->con1 = add_exp (str, strend);
  898.       opP->mode = IMMED;
  899.       return OK;
  900.     }                /* Guess what:  A constant.  Shar and enjoy */
  901.  
  902.   i = m68k_reg_parse (&str);
  903.  
  904.   if (i != FAIL)
  905.     {
  906.       if (*str == '/' || *str == '-')
  907.     {
  908.       /* "Rm-Rn/Ro-Rp"  Register list for MOVEM instruction */
  909.       opP->mode = REGLST;
  910.       return get_regs (i, str, opP);
  911.     }
  912.       if (*str == '\0')
  913.     {
  914.       opP->reg = i;
  915.       /* "Rn"  Register Direct mode */
  916.       if (i >= DATA + 0 && i <= DATA + 7)
  917.         opP->mode = DREG;
  918.       else if (i >= ADDR + 0 && i <= ADDR + 7)
  919.         opP->mode = AREG;
  920.       else
  921.         opP->mode = MSCR;
  922.       return OK;
  923.     }
  924.     }
  925.  
  926.   if (*str != '@')
  927.     {
  928.       char *stmp;
  929.  
  930.       if ((stmp = strchr (str, '@')) != 0)
  931.     {
  932.       opP->con1 = add_exp (str, stmp - 1);
  933.       if (stmp == strend)
  934.         {
  935.           opP->mode = AINDX;
  936.           return (OK);
  937.         }
  938.  
  939.       if ((current_architecture & m68020up) == 0)
  940.         {
  941.           return (FAIL);
  942.         }            /* if target is not a '20 or better */
  943.  
  944.       stmp++;
  945.       if (*stmp++ != '(' || *strend-- != ')')
  946.         {
  947.           opP->error = "Malformed operand";
  948.           return (FAIL);
  949.         }
  950.       i = try_index (&stmp, opP);
  951.       opP->con2 = add_exp (stmp, strend);
  952.  
  953.       if (i == FAIL)
  954.         {
  955.           opP->mode = AMIND;
  956.         }
  957.       else
  958.         {
  959.           opP->mode = APODX;
  960.         }
  961.       return (OK);
  962.     }            /* if there's an '@' */
  963.  
  964. #ifndef MIT_SYNTAX_ONLY
  965.       /* The operand has no '@'.  Try to parse it using
  966.      Motorola syntax.  */
  967.       /* Logic of the parsing switch(*str):
  968.            case            opP->mode =
  969.            ----            -----------
  970.            #anything        IMMED    1
  971.            REG                AREG or DREG or MSCR    3 or 2 or 13
  972.            REG- or REG/            REGLST    14
  973.            (REG)        AINDR    4
  974.            (REG)+            AINC       6
  975.            (REG,INDX)            AINDX    8
  976.            (EXPR,REG)            AOFF       7
  977.            (EXPR,REG,INDX)      AINDX    8
  978.            -(REG)              ADEC       5
  979.            EXP2(REG)        AOFF       7
  980.            EXP2(REG,INDX)    AINDX    8
  981.            EXP2            ABSL       12
  982.  
  983.            REG  means truth(m68k_reg_parse(&str))
  984.            INDX means truth(try_moto_index(&str,opP))
  985.            EXPR means not REG
  986.            EXP2 means not REG and not '(' and not '-('
  987.            */
  988.  
  989.       if (*str == '(')
  990.     {
  991.       str++;
  992.       i = m68k_reg_parse (&str);
  993.       if ((i < ADDR + 0 || i > ADDR + 7)
  994.           && (i < DATA + 0 || i > DATA + 7
  995.           || *str != ')' || str[1] != '0')
  996.           && i != PC && i != ZPC && i != FAIL)
  997.         {
  998.           /* Can't indirect off non address regs */
  999.           opP->error = "Invalid indirect register";
  1000.           return FAIL;
  1001.         }
  1002.       if (i != FAIL)
  1003.         {
  1004.           opP->reg = i;
  1005.           if (*str == ')')
  1006.         {
  1007.           str++;
  1008.           if (*str == '\0')
  1009.             {
  1010.               /* "(An)"  Address Register Indirect mode
  1011.                      or "(Dn)" for cas2.  */
  1012.               if (i >= DATA + 0 && i <= DATA + 7)
  1013.             opP->mode = DINDR;
  1014.               else
  1015.             opP->mode = AINDR;
  1016.               return OK;
  1017.             }
  1018.           if (*str == '+')
  1019.             {
  1020.               if (str[1] == '\0')
  1021.             {
  1022.               /* "(An)+" Register Indirect w Postincrement */
  1023.               opP->mode = AINC;
  1024.               return OK;
  1025.             }
  1026.             }
  1027.           opP->error = "Junk after indirect";
  1028.           return FAIL;
  1029.         }
  1030.           if (*str == ',')
  1031.         {
  1032.           str++;
  1033.           i = try_moto_index (&str, opP);
  1034.           if (i == FAIL)
  1035.             return FAIL;
  1036.           /* "(An,Rn)"  Register Indirect with Index mode*/
  1037.           opP->mode = AINDX;
  1038.           return OK;
  1039.         }
  1040.           else
  1041.         {
  1042.           opP->error = "Bad indirect syntax";
  1043.           return FAIL;
  1044.         }
  1045.         }
  1046.       else
  1047.         {
  1048.           /* "(EXPR,..." , a displacement */
  1049.           char *stmp;
  1050.  
  1051.           if ((stmp = strchr (str, ',')) != NULL)
  1052.         {
  1053.           opP->con1 = add_exp (str, stmp - 1);
  1054.           str = stmp;
  1055.           SKIP_WHITE ();
  1056.           i = m68k_reg_parse (&str);
  1057.           if ((i < ADDR + 0 || i > ADDR + 7) && i != PC && i != ZPC)
  1058.             {
  1059.               /* Can't indirect off non address regs */
  1060.               opP->error = "Invalid indirect register";
  1061.               return FAIL;
  1062.             }
  1063.           if (i != FAIL)
  1064.             {
  1065.               opP->reg = i;
  1066.               if (*str == ')')
  1067.             {
  1068.               /* "(d,An)"  Register Indirect w Displacement */
  1069.               opP->mode = AOFF;
  1070.               return OK;
  1071.             }
  1072.               if (*str == ',')
  1073.             {
  1074.               str++;
  1075.               i = try_moto_index (&str, opP);
  1076.               if (i == FAIL)
  1077.                 return FAIL;
  1078.               /* "(d,An,Rn)"  Register Indirect with Index */
  1079.               opP->mode = AINDX;
  1080.               return OK;
  1081.             }
  1082.               else
  1083.             {
  1084.               opP->error = "Bad indirect syntax";
  1085.               return FAIL;
  1086.             }
  1087.             }
  1088.           else
  1089.             {
  1090.               opP->error = "Invalid register";
  1091.               return FAIL;
  1092.             }
  1093.         }
  1094.           else
  1095.         {
  1096.           opP->mode = ABSL;
  1097.           opP->con1 = add_exp (str - 1, strend);
  1098.           return OK;
  1099.         }
  1100.         }
  1101.     }
  1102.  
  1103.       if (*str == '-')
  1104.     {
  1105.       if (str[1] == '(')
  1106.         {
  1107.           str = str + 2;
  1108.           i = m68k_reg_parse (&str);
  1109.           if ((i < ADDR + 0 || i > ADDR + 7) && i != PC && i != ZPC && i != FAIL)
  1110.         {
  1111.           /* Can't indirect off non address regs */
  1112.           opP->error = "Invalid indirect register";
  1113.           return FAIL;
  1114.         }
  1115.           if (i != FAIL)
  1116.         {
  1117.           opP->reg = i;
  1118.           if (*str == ')')
  1119.             {
  1120.               str++;
  1121.               if (*str == '\0')
  1122.             {
  1123.               /* "-(An)" Register Indirect with Predecrement */
  1124.               opP->mode = ADEC;
  1125.               return OK;
  1126.             }
  1127.               opP->error = "Junk after indirect";
  1128.               return FAIL;
  1129.             }
  1130.           opP->error = "Bad indirect syntax";
  1131.           return FAIL;
  1132.         }
  1133.           opP->mode = ABSL;
  1134.           opP->con1 = add_exp (str - 2, strend);
  1135.           return OK;
  1136.         }
  1137.       /* if '-' but not "-(', do nothing */
  1138.     }
  1139.  
  1140.       /* whether *str=='-' or not */
  1141.       {
  1142.     /* "EXP2" or "EXP2(REG..." */
  1143.     char *stmp;
  1144.     if ((stmp = strchr (str, '(')) != NULL)
  1145.       {
  1146.         char *ostr = str;
  1147.  
  1148.         opP->con1 = add_exp (str, stmp - 1);
  1149.         str = stmp + 1;
  1150.         i = m68k_reg_parse (&str);
  1151.         if ((i < ADDR + 0 || i > ADDR + 7) && i != PC
  1152.         && i != ZPC && i != FAIL)
  1153.           {
  1154.         /* Can't indirect off non address regs */
  1155.         opP->error = "Invalid indirect register";
  1156.         return FAIL;
  1157.           }
  1158.         if (i != FAIL)
  1159.           {
  1160.         opP->reg = i;
  1161.         if (*str == ')')
  1162.           {
  1163.             /* "d(An)"  Register Indirect w Displacement */
  1164.             opP->mode = AOFF;
  1165.             return OK;
  1166.           }
  1167.         if (*str == ',')
  1168.           {
  1169.             str++;
  1170.             i = try_moto_index (&str, opP);
  1171.             if (i == FAIL)
  1172.               return FAIL;
  1173.             /* "d(An,Rn)"  Register Indirect with Index */
  1174.             opP->mode = AINDX;
  1175.             return OK;
  1176.           }
  1177.         else
  1178.           {
  1179.             opP->error = "Bad indirect syntax";
  1180.             return FAIL;
  1181.           }
  1182.           }
  1183.         else
  1184.           {
  1185.         opP->mode = ABSL;
  1186.         opP->con1 = add_exp (ostr, strend);
  1187.         return OK;
  1188.           }
  1189.       }
  1190.     else
  1191.       {
  1192.         /* "EXP2"  Absolute */
  1193.         opP->mode = ABSL;
  1194.         opP->isiz = 0;
  1195.         if (strend[-1] == '.' || strend[-1] == ':')
  1196.           {
  1197.         /* mode ==foo.[wl] */
  1198.         switch (*strend)
  1199.           {
  1200.           case 'w':
  1201.           case 'W':
  1202.             opP->isiz = 2;
  1203.             break;
  1204.           case 'l':
  1205.           case 'L':
  1206.             opP->isiz = 3;
  1207.             break;
  1208.           }
  1209.           }
  1210.         opP->con1 = add_exp (str, strend);
  1211.         return OK;
  1212.       }
  1213.       }
  1214.       /*NOTREACHED*/
  1215. #else /* defined (MIT_SYNTAX_ONLY) */
  1216.       opP->mode = ABSL;
  1217.       opP->con1 = add_exp (str, strend);
  1218.       return OK;
  1219. #endif /* defined (MIT_SYNTAX_ONLY) */
  1220.     }
  1221.  
  1222.   opP->reg = i;
  1223.  
  1224.   /* Can't indirect off non address regs, but Dx@ is OK for cas2 */
  1225.   if ((i < ADDR + 0 || i > ADDR + 7) && i != PC && i != ZPC && i != FAIL
  1226.       && (str[1] != '\0' || i < DATA + 0 || i > DATA + 7))
  1227.     {
  1228.       opP->error = "Invalid indirect register";
  1229.       return FAIL;
  1230.     }
  1231.   know (*str == '@');
  1232.  
  1233.   str++;
  1234.   switch (*str)
  1235.     {
  1236.     case '\0':
  1237.       if (i < DATA + 0 || i > DATA + 7)
  1238.     opP->mode = AINDR;
  1239.       else
  1240.     opP->mode = DINDR;
  1241.       return OK;
  1242.     case '-':
  1243.       opP->mode = ADEC;
  1244.       return OK;
  1245.     case '+':
  1246.       opP->mode = AINC;
  1247.       return OK;
  1248.     case '(':
  1249.       str++;
  1250.       break;
  1251.     default:
  1252.       opP->error = "Junk after indirect";
  1253.       return FAIL;
  1254.     }
  1255.   /* Some kind of indexing involved.  Lets find out how bad it is */
  1256.   i = try_index (&str, opP);
  1257.   /* Didn't start with an index reg, maybe its offset or offset,reg */
  1258.   if (i == FAIL)
  1259.     {
  1260.       char *beg_str;
  1261.  
  1262.       beg_str = str;
  1263.       for (i = 1; i;)
  1264.     {
  1265.       switch (*str++)
  1266.         {
  1267.         case '\0':
  1268.           opP->error = "Missing )";
  1269.           return FAIL;
  1270.         case ',':
  1271.           i = 0;
  1272.           break;
  1273.         case '(':
  1274.           i++;
  1275.           break;
  1276.         case ')':
  1277.           --i;
  1278.           break;
  1279.         }
  1280.     }
  1281. #if 0
  1282.       if (str[-3]==':')
  1283.     {
  1284.       int siz;
  1285.  
  1286.       switch (str[-2])
  1287.         {
  1288.         case 'b':
  1289.         case 'B':
  1290.           siz=1;
  1291.           break;
  1292.         case 'w':
  1293.         case 'W':
  1294.           siz=2;
  1295.           break;
  1296.         case 'l':
  1297.         case 'L':
  1298.           siz=3;
  1299.           break;
  1300.         default:
  1301.           opP->error="Specified size isn't :w or :l";
  1302.           return FAIL;
  1303.         }
  1304.       opP->con1=add_exp(beg_str,str-4);
  1305.       opP->con1->e_siz=siz;
  1306.     }
  1307.       else
  1308. #endif
  1309.     opP->con1 = add_exp (beg_str, str - 2);
  1310.       /* Should be offset,reg */
  1311.       if (str[-1] == ',')
  1312.     {
  1313.       i = try_index (&str, opP);
  1314.       if (i == FAIL)
  1315.         {
  1316.           opP->error = "Malformed index reg";
  1317.           return FAIL;
  1318.         }
  1319.     }
  1320.     }
  1321.   /* We've now got offset)   offset,reg)   or    reg) */
  1322.  
  1323.   if (*str == '\0')
  1324.     {
  1325.       /* Th-the-thats all folks */
  1326.       if (opP->reg == FAIL)
  1327.     opP->mode = AINDX;    /* Other form of indirect */
  1328.       else if (opP->ireg == FAIL)
  1329.     opP->mode = AOFF;
  1330.       else
  1331.     opP->mode = AINDX;
  1332.       return (OK);
  1333.     }
  1334.   /* Next thing had better be another @ */
  1335.   if (*str == '@')
  1336.     {
  1337.       if (str[1] == '(')
  1338.     {
  1339.       needp = 1;
  1340.       str += 2;
  1341.     }
  1342.       else
  1343.     {
  1344.       needp = 0;
  1345.       str++;
  1346.     }
  1347.     }
  1348.  
  1349.   if ((current_architecture & m68020up) == 0)
  1350.     {
  1351.       return (FAIL);
  1352.     }                /* if target is not a '20 or better */
  1353.  
  1354.  
  1355.   if (opP->ireg != FAIL)
  1356.     {
  1357.       opP->mode = APRDX;
  1358.  
  1359.       i = try_index (&str, opP);
  1360.       if (i != FAIL)
  1361.     {
  1362.       opP->error = "Two index registers!  not allowed!";
  1363.       return (FAIL);
  1364.     }
  1365.     }
  1366.   else
  1367.     {
  1368.       i = try_index (&str, opP);
  1369.     }
  1370.  
  1371.   if (i == FAIL)
  1372.     {
  1373.       char *beg_str;
  1374.  
  1375.       beg_str = str;
  1376.  
  1377.       for (i = 1; i;)
  1378.     {
  1379.       switch (*str++)
  1380.         {
  1381.         case '\0':
  1382.           if (needp)
  1383.         opP->error = "Missing )";
  1384.           return (FAIL);
  1385.           break;
  1386.         case ',':
  1387.           i = 0;
  1388.           break;
  1389.         case '(':
  1390.           i++;
  1391.           break;
  1392.         case ')':
  1393.           --i;
  1394.           break;
  1395.         }
  1396.     }
  1397.  
  1398.       opP->con2 = add_exp (beg_str, str - 2);
  1399.  
  1400.       if (str[-1] == ',')
  1401.     {
  1402.       if (opP->ireg != FAIL)
  1403.         {
  1404.           opP->error = "Can't have two index regs";
  1405.           return (FAIL);
  1406.         }
  1407.  
  1408.       i = try_index (&str, opP);
  1409.  
  1410.       if (i == FAIL)
  1411.         {
  1412.           opP->error = "malformed index reg";
  1413.           return (FAIL);
  1414.         }
  1415.  
  1416.       opP->mode = APODX;
  1417.     }
  1418.       else if (opP->ireg != FAIL)
  1419.     {
  1420.       opP->mode = APRDX;
  1421.     }
  1422.       else
  1423.     {
  1424.       opP->mode = AMIND;
  1425.     }
  1426.     }
  1427.   else
  1428.     {
  1429.       opP->mode = APODX;
  1430.     }
  1431.  
  1432.   if (*str != '\0')
  1433.     {
  1434.       opP->error = "Junk after indirect";
  1435.       return FAIL;
  1436.     }
  1437.   return (OK);
  1438. }                /* m68k_ip_op() */
  1439.  
  1440.  
  1441. #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
  1442.  
  1443. #ifdef NO_PCREL_RELOCS
  1444.  
  1445. int
  1446. make_pcrel_absolute(fixP, add_number)
  1447.     fixS *fixP;
  1448.     long *add_number;
  1449. {
  1450.   register unsigned char *opcode = fixP->fx_frag->fr_opcode;
  1451.  
  1452.   /* rewrite the PC relative instructions to absolute address ones.
  1453.    * these are rumoured to be faster, and the apollo linker refuses
  1454.    * to deal with the PC relative relocations.
  1455.    */
  1456.   if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP */
  1457.     {
  1458.       opcode[0] = 0x4e;
  1459.       opcode[1] = 0xf9;
  1460.     }
  1461.   else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR */
  1462.     {
  1463.       opcode[0] = 0x4e;
  1464.       opcode[1] = 0xb9;
  1465.     }
  1466.   else
  1467.     as_fatal ("Unknown PC relative instruction");
  1468.   *add_number -= 4;
  1469.   return 0;
  1470. }
  1471.  
  1472. #endif /* NO_PCREL_RELOCS */
  1473.  
  1474. short
  1475. tc_coff_fix2rtype (fixP)
  1476.      fixS *fixP;
  1477. {
  1478. #ifdef NO_PCREL_RELOCS
  1479.   know (fixP->fx_pcrel == 0);
  1480.   return (fixP->fx_size == 1 ? R_RELBYTE
  1481.       : fixP->fx_size == 2 ? R_DIR16
  1482.       : R_DIR32);
  1483. #else
  1484.   return (fixP->fx_pcrel ?
  1485.       (fixP->fx_size == 1 ? R_PCRBYTE :
  1486.        fixP->fx_size == 2 ? R_PCRWORD :
  1487.        R_PCRLONG) :
  1488.       (fixP->fx_size == 1 ? R_RELBYTE :
  1489.        fixP->fx_size == 2 ? R_RELWORD :
  1490.        R_RELLONG));
  1491. #endif
  1492. }
  1493.  
  1494. #endif
  1495.  
  1496. #ifdef BFD_ASSEMBLER
  1497.  
  1498. arelent *
  1499. tc_gen_reloc (section, fixp)
  1500.      asection *section;
  1501.      fixS *fixp;
  1502. {
  1503.   arelent *reloc;
  1504.   bfd_reloc_code_real_type code;
  1505.  
  1506. #define F(SZ,PCREL)        (((SZ) << 1) + (PCREL))
  1507.   switch (F (fixp->fx_size, fixp->fx_pcrel))
  1508.     {
  1509. #define MAP(SZ,PCREL,TYPE)    case F(SZ,PCREL): code = (TYPE); break
  1510.       MAP (1, 0, BFD_RELOC_8);
  1511.       MAP (2, 0, BFD_RELOC_16);
  1512.       MAP (4, 0, BFD_RELOC_32);
  1513.       MAP (1, 1, BFD_RELOC_8_PCREL);
  1514.       MAP (2, 1, BFD_RELOC_16_PCREL);
  1515.       MAP (4, 1, BFD_RELOC_32_PCREL);
  1516.     default:
  1517.       abort ();
  1518.     }
  1519.  
  1520.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  1521.   assert (reloc != 0);
  1522.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  1523.   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1524.   if (fixp->fx_pcrel)
  1525.     reloc->addend = fixp->fx_addnumber;
  1526.   else
  1527.     reloc->addend = 0;
  1528.  
  1529.   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  1530.   assert (reloc->howto != 0);
  1531.  
  1532.   return reloc;
  1533. }
  1534.  
  1535. #endif /* BFD_ASSEMBLER */
  1536.  
  1537. #ifdef TEST1            /* TEST1 tests m68k_ip_op(), which parses operands */
  1538. main ()
  1539. {
  1540.   char buf[128];
  1541.   struct m68k_op thark;
  1542.  
  1543.   for (;;)
  1544.     {
  1545.       if (!gets (buf))
  1546.     break;
  1547.       memset (&thark, '\0', sizeof (thark));
  1548.       if (!m68k_ip_op (buf, &thark))
  1549.     printf ("FAIL:");
  1550.       if (thark.error)
  1551.     printf ("op1 error %s in %s\n", thark.error, buf);
  1552.       printf ("mode %d, reg %d, ", thark.mode, thark.reg);
  1553.       if (thark.b_const)
  1554.     printf ("Constant: '%.*s',", 1 + thark.e_const - thark.b_const, thark.b_const);
  1555.       printf ("ireg %d, isiz %d, imul %d ", thark.ireg, thark.isiz, thark.imul);
  1556.       if (thark.b_iadd)
  1557.     printf ("Iadd: '%.*s'", 1 + thark.e_iadd - thark.b_iadd, thark.b_iadd);
  1558.       printf ("\n");
  1559.     }
  1560.   exit (EXIT_SUCCESS);
  1561. }
  1562.  
  1563. #endif
  1564.  
  1565.  
  1566. /* Handle of the OPCODE hash table.  NULL means any use before
  1567.    m68k_ip_begin() will crash.  */
  1568. static struct hash_control *op_hash;
  1569.  
  1570.  
  1571. /*
  1572.  *        m 6 8 k _ i p ( )
  1573.  *
  1574.  * This converts a string into a 68k instruction.
  1575.  * The string must be a bare single instruction in sun format
  1576.  * with RMS-style 68020 indirects
  1577.  *  (example:  )
  1578.  *
  1579.  * It provides some error messages: at most one fatal error message (which
  1580.  * stops the scan) and at most one warning message for each operand.
  1581.  * The 68k instruction is returned in exploded form, since we have no
  1582.  * knowledge of how you parse (or evaluate) your expressions.
  1583.  * We do however strip off and decode addressing modes and operation
  1584.  * mnemonic.
  1585.  *
  1586.  * This function's value is a string. If it is not "" then an internal
  1587.  * logic error was found: read this code to assign meaning to the string.
  1588.  * No argument string should generate such an error string:
  1589.  * it means a bug in our code, not in the user's text.
  1590.  *
  1591.  * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
  1592.  * this function.
  1593.  */
  1594.  
  1595. /* JF this function no longer returns a useful value.  Sorry */
  1596. void
  1597. m68k_ip (instring)
  1598.      char *instring;
  1599. {
  1600.   register char *p;
  1601.   register struct m68k_op *opP;
  1602.   register struct m68k_incant *opcode;
  1603.   register char *s;
  1604.   register int tmpreg = 0, baseo = 0, outro = 0, nextword;
  1605.   char *pdot, *pdotmove;
  1606.   int siz1, siz2;
  1607.   char c;
  1608.   int losing;
  1609.   int opsfound;
  1610.   char *crack_operand ();
  1611.   LITTLENUM_TYPE words[6];
  1612.   LITTLENUM_TYPE *wordp;
  1613.   unsigned long ok_arch = 0;
  1614.  
  1615.   if (*instring == ' ')
  1616.     instring++;            /* skip leading whitespace */
  1617.  
  1618.   /* Scan up to end of operation-code, which MUST end in end-of-string
  1619.      or exactly 1 space. */
  1620.   pdot = 0;
  1621.   for (p = instring; *p != '\0'; p++)
  1622.     {
  1623.       if (*p == ' ')
  1624.     break;
  1625.       if (*p == '.')
  1626.     pdot = p;
  1627.     }
  1628.  
  1629.   if (p == instring)
  1630.     {
  1631.       the_ins.error = "No operator";
  1632.       the_ins.opcode[0] = 0;
  1633.       /* the_ins.numo=1; */
  1634.       return;
  1635.     }
  1636.  
  1637.   /* p now points to the end of the opcode name, probably whitespace.
  1638.      make sure the name is null terminated by clobbering the whitespace,
  1639.      look it up in the hash table, then fix it back.
  1640.      Remove a dot, first, since the opcode tables have none.  */
  1641.   if (pdot != NULL)
  1642.     {
  1643.       for (pdotmove = pdot; pdotmove < p; pdotmove++)
  1644.     *pdotmove = pdotmove[1];
  1645.       p--;
  1646.     }
  1647.  
  1648.   c = *p;
  1649.   *p = '\0';
  1650.   opcode = (struct m68k_incant *) hash_find (op_hash, instring);
  1651.   *p = c;
  1652.  
  1653.   if (pdot != NULL)
  1654.     {
  1655.       for (pdotmove = p; pdotmove > pdot; pdotmove--)
  1656.     *pdotmove = pdotmove[-1];
  1657.       *pdot = '.';
  1658.       ++p;
  1659.     }
  1660.  
  1661.   if (opcode == NULL)
  1662.     {
  1663.       the_ins.error = "Unknown operator";
  1664.       the_ins.opcode[0] = 0;
  1665.       /* the_ins.numo=1; */
  1666.       return;
  1667.     }
  1668.  
  1669.   /* found a legitimate opcode, start matching operands */
  1670.   while (*p == ' ')
  1671.     ++p;
  1672.  
  1673.  
  1674.   if (opcode->m_operands == 0)
  1675.     {
  1676.       char *old = input_line_pointer;
  1677.       *old = '\n';
  1678.       input_line_pointer = p;
  1679.       /* Ahh - it's a motorola style psuedo op */
  1680.       mote_pseudo_table[opcode->m_opnum].poc_handler
  1681.     (mote_pseudo_table[opcode->m_opnum].poc_val);
  1682.       input_line_pointer = old;
  1683.       *old = 0;
  1684.  
  1685.       return;
  1686.     }
  1687.  
  1688.   for (opP = &the_ins.operands[0]; *p; opP++)
  1689.     {
  1690.  
  1691.       p = crack_operand (p, opP);
  1692.  
  1693.       if (opP->error)
  1694.     {
  1695.       the_ins.error = opP->error;
  1696.       return;
  1697.     }
  1698.     }
  1699.  
  1700.   opsfound = opP - &the_ins.operands[0];
  1701.  
  1702.   /* This ugly hack is to support the floating pt opcodes in their standard form */
  1703.   /* Essentially, we fake a first enty of type COP#1 */
  1704.   if (opcode->m_operands[0] == 'I')
  1705.     {
  1706.       int n;
  1707.  
  1708.       for (n = opsfound; n > 0; --n)
  1709.     the_ins.operands[n] = the_ins.operands[n - 1];
  1710.  
  1711.       memset ((char *) (&the_ins.operands[0]), '\0', sizeof (the_ins.operands[0]));
  1712.       the_ins.operands[0].mode = MSCR;
  1713.       the_ins.operands[0].reg = COPNUM;    /* COP #1 */
  1714.       opsfound++;
  1715.     }
  1716.  
  1717.   /* We've got the operands.  Find an opcode that'll accept them */
  1718.   for (losing = 0;;)
  1719.     {
  1720.       /* If we didn't get the right number of ops, or we have no
  1721.      common model with this pattern then reject this pattern. */
  1722.  
  1723.       if (opsfound != opcode->m_opnum
  1724.       || ((opcode->m_arch & current_architecture) == 0))
  1725.     {
  1726.       ++losing;
  1727.       ok_arch |= opcode->m_arch;
  1728.     }
  1729.       else
  1730.     {
  1731.       for (s = opcode->m_operands, opP = &the_ins.operands[0]; *s && !losing; s += 2, opP++)
  1732.         {
  1733.           /* Warning: this switch is huge! */
  1734.           /* I've tried to organize the cases into this order:
  1735.          non-alpha first, then alpha by letter.  Lower-case
  1736.          goes directly before uppercase counterpart.  */
  1737.           /* Code with multiple case ...: gets sorted by the lowest
  1738.          case ... it belongs to.  I hope this makes sense.  */
  1739.           switch (*s)
  1740.         {
  1741.         case '!':
  1742.           if (opP->mode == MSCR || opP->mode == IMMED
  1743.               || opP->mode == DREG || opP->mode == AREG
  1744.               || opP->mode == AINC || opP->mode == ADEC
  1745.               || opP->mode == REGLST)
  1746.             losing++;
  1747.           break;
  1748.  
  1749.         case '`':
  1750.           switch (opP->mode)
  1751.             {
  1752.             case MSCR:
  1753.             case IMMED:
  1754.             case DREG:
  1755.             case AREG:
  1756.             case AINC:
  1757.             case REGLST:
  1758.             case AINDR:
  1759.               losing++;
  1760.               break;
  1761.             default:
  1762.               break;
  1763.             }
  1764.           break;
  1765.  
  1766.         case '#':
  1767.           if (opP->mode != IMMED)
  1768.             losing++;
  1769.           else
  1770.             {
  1771.               long t;
  1772.  
  1773.               t = get_num (opP->con1, 80);
  1774.               if (s[1] == 'b' && !isbyte (t))
  1775.             losing++;
  1776.               else if (s[1] == 'w' && !isword (t))
  1777.             losing++;
  1778.             }
  1779.           break;
  1780.  
  1781.         case '^':
  1782.         case 'T':
  1783.           if (opP->mode != IMMED)
  1784.             losing++;
  1785.           break;
  1786.  
  1787.         case '$':
  1788.           if (opP->mode == MSCR || opP->mode == AREG ||
  1789.               opP->mode == IMMED || opP->reg == PC || opP->reg == ZPC || opP->mode == REGLST)
  1790.             losing++;
  1791.           break;
  1792.  
  1793.         case '%':
  1794.           if (opP->mode == MSCR || opP->reg == PC ||
  1795.               opP->reg == ZPC || opP->mode == REGLST)
  1796.             losing++;
  1797.           break;
  1798.  
  1799.  
  1800.         case '&':
  1801.           if (opP->mode == MSCR || opP->mode == DREG ||
  1802.               opP->mode == AREG || opP->mode == IMMED || opP->reg == PC || opP->reg == ZPC ||
  1803.               opP->mode == AINC || opP->mode == ADEC || opP->mode == REGLST)
  1804.             losing++;
  1805.           break;
  1806.  
  1807.         case '*':
  1808.           if (opP->mode == MSCR || opP->mode == REGLST)
  1809.             losing++;
  1810.           break;
  1811.  
  1812.         case '+':
  1813.           if (opP->mode != AINC)
  1814.             losing++;
  1815.           break;
  1816.  
  1817.         case '-':
  1818.           if (opP->mode != ADEC)
  1819.             losing++;
  1820.           break;
  1821.  
  1822.         case '/':
  1823.           if (opP->mode == MSCR || opP->mode == AREG ||
  1824.               opP->mode == AINC || opP->mode == ADEC || opP->mode == IMMED || opP->mode == REGLST)
  1825.             losing++;
  1826.           break;
  1827.  
  1828.         case ';':
  1829.           if (opP->mode == MSCR || opP->mode == AREG || opP->mode == REGLST)
  1830.             losing++;
  1831.           break;
  1832.  
  1833.         case '?':
  1834.           if (opP->mode == MSCR || opP->mode == AREG ||
  1835.               opP->mode == AINC || opP->mode == ADEC || opP->mode == IMMED || opP->reg == PC ||
  1836.               opP->reg == ZPC || opP->mode == REGLST)
  1837.             losing++;
  1838.           break;
  1839.  
  1840.         case '@':
  1841.           if (opP->mode == MSCR || opP->mode == AREG ||
  1842.               opP->mode == IMMED || opP->mode == REGLST)
  1843.             losing++;
  1844.           break;
  1845.  
  1846.         case '~':    /* For now! (JF FOO is this right?) */
  1847.           if (opP->mode == MSCR || opP->mode == DREG ||
  1848.               opP->mode == AREG || opP->mode == IMMED || opP->reg == PC || opP->reg == ZPC || opP->mode == REGLST)
  1849.             losing++;
  1850.           break;
  1851.  
  1852.         case '3':
  1853.           if (opP->mode != MSCR || (opP->reg != TT0 && opP->reg != TT1))
  1854.             losing++;
  1855.           break;
  1856.  
  1857.         case 'A':
  1858.           if (opP->mode != AREG)
  1859.             losing++;
  1860.           break;
  1861.         case 'a':
  1862.           if (opP->mode != AINDR)
  1863.             {
  1864.               ++losing;
  1865.             }        /* if not address register indirect */
  1866.           break;
  1867.         case 'B':    /* FOO */
  1868.           if (opP->mode != ABSL || (flag_long_jumps && instring[0] == 'j'
  1869.                         && instring[1] == 'b'
  1870.                         && instring[2] == 's'
  1871.                         && instring[3] == 'r'))
  1872.             losing++;
  1873.           break;
  1874.  
  1875.         case 'C':
  1876.           if (opP->mode != MSCR || opP->reg != CCR)
  1877.             losing++;
  1878.           break;
  1879.  
  1880.         case 'd':    /* FOO This mode is a KLUDGE!! */
  1881.           if (opP->mode != AOFF && (opP->mode != ABSL ||
  1882.           opP->con1->e_beg[0] != '(' || opP->con1->e_end[0] != ')'))
  1883.             losing++;
  1884.           break;
  1885.  
  1886.         case 'D':
  1887.           if (opP->mode != DREG)
  1888.             losing++;
  1889.           break;
  1890.  
  1891.         case 'F':
  1892.           if (opP->mode != MSCR || opP->reg < (FPREG + 0) || opP->reg > (FPREG + 7))
  1893.             losing++;
  1894.           break;
  1895.  
  1896.         case 'I':
  1897.           if (opP->mode != MSCR || opP->reg < COPNUM ||
  1898.               opP->reg >= COPNUM + 7)
  1899.             losing++;
  1900.           break;
  1901.  
  1902.         case 'J':
  1903.           if (opP->mode != MSCR
  1904.               || opP->reg < USP
  1905.               || opP->reg > last_movec_reg)
  1906.             losing++;
  1907.           else
  1908.             {
  1909.               const enum _register *rp;
  1910.               for (rp = control_regs; *rp; rp++)
  1911.             if (*rp == opP->reg)
  1912.               break;
  1913.               if (*rp == 0)
  1914.             losing++;
  1915.             }
  1916.           break;
  1917.  
  1918.         case 'k':
  1919.           if (opP->mode != IMMED)
  1920.             losing++;
  1921.           break;
  1922.  
  1923.         case 'l':
  1924.         case 'L':
  1925.           if (opP->mode == DREG || opP->mode == AREG || opP->mode == FPREG)
  1926.             {
  1927.               if (s[1] == '8')
  1928.             losing++;
  1929.               else
  1930.             {
  1931.               opP->mode = REGLST;
  1932.               opP->reg = 1 << (opP->reg - DATA);
  1933.             }
  1934.             }
  1935.           else if (opP->mode != REGLST)
  1936.             {
  1937.               losing++;
  1938.             }
  1939.           else if (s[1] == '8' && opP->reg & 0x0FFffFF)
  1940.             losing++;
  1941.           else if (s[1] == '3' && opP->reg & 0x7000000)
  1942.             losing++;
  1943.           break;
  1944.  
  1945.         case 'M':
  1946.           if (opP->mode != IMMED)
  1947.             losing++;
  1948.           else
  1949.             {
  1950.               long t;
  1951.  
  1952.               t = get_num (opP->con1, 0);
  1953.               if (!issbyte (t)
  1954.               || isvar (opP->con1))
  1955.             losing++;
  1956.             }
  1957.           break;
  1958.  
  1959.         case 'O':
  1960.           if (opP->mode != DREG && opP->mode != IMMED)
  1961.             losing++;
  1962.           break;
  1963.  
  1964.         case 'Q':
  1965.           if (opP->mode != IMMED)
  1966.             losing++;
  1967.           else
  1968.             {
  1969.               long t;
  1970.  
  1971.               t = get_num (opP->con1, 80);
  1972.               if (t < 1 || t > 8 || isvar (opP->con1))
  1973.             losing++;
  1974.             }
  1975.           break;
  1976.  
  1977.         case 'R':
  1978.           if (opP->mode != DREG && opP->mode != AREG)
  1979.             losing++;
  1980.           break;
  1981.  
  1982.         case 'r':
  1983.           if (opP->mode != AINDR && opP->mode != DINDR)
  1984.             losing++;
  1985.           break;
  1986.  
  1987.         case 's':
  1988.           if (opP->mode != MSCR || !(opP->reg == FPI || opP->reg == FPS || opP->reg == FPC))
  1989.             losing++;
  1990.           break;
  1991.  
  1992.         case 'S':
  1993.           if (opP->mode != MSCR || opP->reg != SR)
  1994.             losing++;
  1995.           break;
  1996.  
  1997.         case 't':
  1998.           if (opP->mode != IMMED)
  1999.             losing++;
  2000.           else
  2001.             {
  2002.               long t = get_num (opP->con1, 80);
  2003.               if (t < 0 || t > 7 || isvar (opP->con1))
  2004.             losing++;
  2005.             }
  2006.           break;
  2007.  
  2008.         case 'U':
  2009.           if (opP->mode != MSCR || opP->reg != USP)
  2010.             losing++;
  2011.           break;
  2012.  
  2013.           /* JF these are out of order.  We could put them
  2014.              in order if we were willing to put up with
  2015.              bunches of #ifdef m68851s in the code.
  2016.  
  2017.              Don't forget that you need these operands
  2018.              to use 68030 MMU instructions.  */
  2019. #ifndef NO_68851
  2020.           /* Memory addressing mode used by pflushr */
  2021.         case '|':
  2022.           if (opP->mode == MSCR || opP->mode == DREG ||
  2023.               opP->mode == AREG || opP->mode == REGLST)
  2024.             losing++;
  2025.           break;
  2026.  
  2027.         case 'f':
  2028.           if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
  2029.             losing++;
  2030.           break;
  2031.  
  2032.         case 'P':
  2033.           if (opP->mode != MSCR
  2034.               || (opP->reg != TC && opP->reg != CAL
  2035.            && opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
  2036.             losing++;
  2037.           break;
  2038.  
  2039.         case 'V':
  2040.           if (opP->reg != VAL)
  2041.             losing++;
  2042.           break;
  2043.  
  2044.         case 'W':
  2045.           if (opP->mode != MSCR
  2046.               || (opP->reg != DRP && opP->reg != SRP
  2047.               && opP->reg != CRP))
  2048.             losing++;
  2049.           break;
  2050.  
  2051.         case 'X':
  2052.           if (opP->mode != MSCR ||
  2053.               (!(opP->reg >= BAD && opP->reg <= BAD + 7) &&
  2054.                !(opP->reg >= BAC && opP->reg <= BAC + 7)))
  2055.             losing++;
  2056.           break;
  2057.  
  2058.         case 'Y':
  2059.           if (opP->reg != PSR)
  2060.             losing++;
  2061.           break;
  2062.  
  2063.         case 'Z':
  2064.           if (opP->reg != PCSR)
  2065.             losing++;
  2066.           break;
  2067. #endif
  2068.         case 'c':
  2069.           if (opP->reg != NC
  2070.               && opP->reg != IC
  2071.               && opP->reg != DC
  2072.               && opP->reg != BC)
  2073.             {
  2074.               losing++;
  2075.             }        /* not a cache specifier. */
  2076.           break;
  2077.  
  2078.         case '_':
  2079.           if (opP->mode != ABSL)
  2080.             {
  2081.               ++losing;
  2082.             }        /* not absolute */
  2083.           break;
  2084.  
  2085.         default:
  2086.           as_fatal ("Internal error:  Operand mode %c unknown in line %d of file \"%s\"",
  2087.                 *s, __LINE__, __FILE__);
  2088.         }        /* switch on type of operand */
  2089.  
  2090.           if (losing)
  2091.         break;
  2092.         }            /* for each operand */
  2093.     }            /* if immediately wrong */
  2094.  
  2095.       if (!losing)
  2096.     {
  2097.       break;
  2098.     }            /* got it. */
  2099.  
  2100.       opcode = opcode->m_next;
  2101.  
  2102.       if (!opcode)
  2103.     {
  2104.       if (ok_arch
  2105.           && !(ok_arch & current_architecture))
  2106.         {
  2107.           char buf[200], *cp;
  2108.           int len;
  2109.           strcpy (buf, "invalid instruction for this architecture; needs ");
  2110.           cp = buf + strlen (buf);
  2111.           switch (ok_arch)
  2112.         {
  2113.         case mfloat:
  2114.           strcpy (cp, "fpu (68040, 68060 or 68881/68882)");
  2115.           break;
  2116.         case mmmu:
  2117.           strcpy (cp, "mmu (68030 or 68851)");
  2118.           break;
  2119.         case m68020up:
  2120.           strcpy (cp, "68020 or higher");
  2121.           break;
  2122.         case m68000up:
  2123.           strcpy (cp, "68000 or higher");
  2124.           break;
  2125.         case m68010up:
  2126.           strcpy (cp, "68010 or higher");
  2127.           break;
  2128.         default:
  2129.           {
  2130.             int got_one = 0, idx;
  2131.             static const struct
  2132.               {
  2133.             int arch;
  2134.             const char *name;
  2135.               }
  2136.             archs[] =
  2137.             {
  2138.               { m68000, "68000" },
  2139.               { m68010, "68010" },
  2140.               { m68020, "68020" },
  2141.               { m68030, "68030" },
  2142.               { m68040, "68040" },
  2143.               { m68060, "68060" },
  2144.               { cpu32,  "cpu32" },
  2145.               { m68881, "68881" },
  2146.               { m68851, "68851" }
  2147.             };
  2148.             for (idx = 0; idx < sizeof (archs) / sizeof (archs[0]); idx++)
  2149.               {
  2150.             if (archs[idx].arch & ok_arch)
  2151.               {
  2152.                 if (got_one)
  2153.                   {
  2154.                 strcpy (cp, " or ");
  2155.                 cp += strlen (cp);
  2156.                   }
  2157.                 got_one = 1;
  2158.                 strcpy (cp, archs[idx].name);
  2159.                 cp += strlen (cp);
  2160.               }
  2161.               }
  2162.           }
  2163.         }
  2164.           len = cp - buf + 1;
  2165.           cp = malloc (len);
  2166.           strcpy (cp, buf);
  2167.           the_ins.error = cp;
  2168.         }
  2169.       else
  2170.         the_ins.error = "operands mismatch";
  2171.       return;
  2172.     }            /* Fell off the end */
  2173.  
  2174.       losing = 0;
  2175.     }
  2176.  
  2177.   /* now assemble it */
  2178.  
  2179.   the_ins.args = opcode->m_operands;
  2180.   the_ins.numargs = opcode->m_opnum;
  2181.   the_ins.numo = opcode->m_codenum;
  2182.   the_ins.opcode[0] = getone (opcode);
  2183.   the_ins.opcode[1] = gettwo (opcode);
  2184.  
  2185.   for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
  2186.     {
  2187.       /* This switch is a doozy.
  2188.        Watch the first step; its a big one! */
  2189.       switch (s[0])
  2190.     {
  2191.  
  2192.     case '*':
  2193.     case '~':
  2194.     case '%':
  2195.     case ';':
  2196.     case '@':
  2197.     case '!':
  2198.     case '&':
  2199.     case '$':
  2200.     case '?':
  2201.     case '/':
  2202.     case '`':
  2203. #ifndef NO_68851
  2204.     case '|':
  2205. #endif
  2206.       switch (opP->mode)
  2207.         {
  2208.         case IMMED:
  2209.           tmpreg = 0x3c;    /* 7.4 */
  2210.           if (strchr ("bwl", s[1]))
  2211.         nextword = get_num (opP->con1, 80);
  2212.           else
  2213.         nextword = get_num (opP->con1, 0);
  2214.           if (isvar (opP->con1))
  2215.         add_fix (s[1], opP->con1, 0);
  2216.           switch (s[1])
  2217.         {
  2218.         case 'b':
  2219.           if (!isbyte (nextword))
  2220.             opP->error = "operand out of range";
  2221.           addword (nextword);
  2222.           baseo = 0;
  2223.           break;
  2224.         case 'w':
  2225.           if (!isword (nextword))
  2226.             opP->error = "operand out of range";
  2227.           addword (nextword);
  2228.           baseo = 0;
  2229.           break;
  2230.         case 'l':
  2231.           addword (nextword >> 16);
  2232.           addword (nextword);
  2233.           baseo = 0;
  2234.           break;
  2235.  
  2236.         case 'f':
  2237.           baseo = 2;
  2238.           outro = 8;
  2239.           break;
  2240.         case 'F':
  2241.           baseo = 4;
  2242.           outro = 11;
  2243.           break;
  2244.         case 'x':
  2245.           baseo = 6;
  2246.           outro = 15;
  2247.           break;
  2248.         case 'p':
  2249.           baseo = 6;
  2250.           outro = -1;
  2251.           break;
  2252.         default:
  2253.           as_fatal ("Internal error:  Can't decode %c%c in line %d of file \"%s\"",
  2254.                 *s, s[1], __LINE__, __FILE__);
  2255.         }
  2256.           if (!baseo)
  2257.         break;
  2258.  
  2259.           /* We gotta put out some float */
  2260.           if (op (opP->con1) != O_big)
  2261.         {
  2262.           valueT val;
  2263.           int gencnt;
  2264.  
  2265.           /* Can other cases happen here?  */
  2266.           if (op (opP->con1) != O_constant)
  2267.             abort ();
  2268.  
  2269.           val = (valueT) offs (opP->con1);
  2270.           gencnt = 0;
  2271.           do
  2272.             {
  2273.               generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
  2274.               val >>= LITTLENUM_NUMBER_OF_BITS;
  2275.               ++gencnt;
  2276.             }
  2277.           while (val != 0);
  2278.           offs (opP->con1) = gencnt;
  2279.         }
  2280.           if (offs (opP->con1) > 0)
  2281.         {
  2282.           if (offs (opP->con1) > baseo)
  2283.             {
  2284.               as_warn ("Bignum too big for %c format; truncated", s[1]);
  2285.               offs (opP->con1) = baseo;
  2286.             }
  2287.           baseo -= offs (opP->con1);
  2288.           while (baseo--)
  2289.             addword (0);
  2290.           for (wordp = generic_bignum + offs (opP->con1) - 1; offs (opP->con1)--; --wordp)
  2291.             addword (*wordp);
  2292.           break;
  2293.         }
  2294.           gen_to_words (words, baseo, (long) outro);
  2295.           for (wordp = words; baseo--; wordp++)
  2296.         addword (*wordp);
  2297.           break;
  2298.         case DREG:
  2299.           tmpreg = opP->reg - DATA;    /* 0.dreg */
  2300.           break;
  2301.         case AREG:
  2302.           tmpreg = 0x08 + opP->reg - ADDR;    /* 1.areg */
  2303.           break;
  2304.         case AINDR:
  2305.           tmpreg = 0x10 + opP->reg - ADDR;    /* 2.areg */
  2306.           break;
  2307.         case ADEC:
  2308.           tmpreg = 0x20 + opP->reg - ADDR;    /* 4.areg */
  2309.           break;
  2310.         case AINC:
  2311.           tmpreg = 0x18 + opP->reg - ADDR;    /* 3.areg */
  2312.           break;
  2313.         case AOFF:
  2314.  
  2315.           nextword = get_num (opP->con1, 80);
  2316.           /* Force into index mode.  Hope this works */
  2317.  
  2318.           /* We do the first bit for 32-bit displacements, and the
  2319.          second bit for 16 bit ones.  It is possible that we
  2320.          should make the default be WORD instead of LONG, but
  2321.          I think that'd break GCC, so we put up with a little
  2322.          inefficiency for the sake of working output.  */
  2323.  
  2324.           if (!issword (nextword)
  2325.           || (isvar (opP->con1)
  2326.               && ((opP->con1->e_siz == 0
  2327.                && flag_short_refs == 0)
  2328.               || opP->con1->e_siz == 3)))
  2329.         {
  2330.  
  2331.           if (opP->reg == PC)
  2332.             tmpreg = 0x3B;    /* 7.3 */
  2333.           else
  2334.             tmpreg = 0x30 + opP->reg - ADDR;    /* 6.areg */
  2335.           if (isvar (opP->con1))
  2336.             {
  2337.               if (opP->reg == PC)
  2338.             {
  2339.               addword (0x0170);
  2340.               opP->con1->e_exp.X_add_number += 6;
  2341.               add_fix ('l', opP->con1, 1);
  2342.               addword (0), addword (0);
  2343.               break;
  2344.             }
  2345.               else
  2346.             {
  2347.               addword (0x0170);
  2348.               add_fix ('l', opP->con1, 0);
  2349.             }
  2350.             }
  2351.           else
  2352.             addword (0x0170);
  2353.           addword (nextword >> 16);
  2354.         }
  2355.           else
  2356.         {
  2357.           if (opP->reg == PC)
  2358.             tmpreg = 0x3A;    /* 7.2 */
  2359.           else
  2360.             tmpreg = 0x28 + opP->reg - ADDR;    /* 5.areg */
  2361.  
  2362.           if (isvar (opP->con1))
  2363.             {
  2364.               if (opP->reg == PC)
  2365.             {
  2366.               opP->con1->e_exp.X_add_number += 2;
  2367.               add_fix ('w', opP->con1, 1);
  2368.             }
  2369.               else
  2370.             add_fix ('w', opP->con1, 0);
  2371.             }
  2372.         }
  2373.           addword (nextword);
  2374.           break;
  2375.  
  2376.         case APODX:
  2377.         case AMIND:
  2378.         case APRDX:
  2379.           know (current_architecture & m68020up);
  2380.           /* intentional fall-through */
  2381.         case AINDX:
  2382.           nextword = 0;
  2383.           baseo = get_num (opP->con1, 80);
  2384.           outro = get_num (opP->con2, 80);
  2385.           /* Figure out the `addressing mode'.
  2386.          Also turn on the BASE_DISABLE bit, if needed.  */
  2387.           if (opP->reg == PC || opP->reg == ZPC)
  2388.         {
  2389.           tmpreg = 0x3b;/* 7.3 */
  2390.           if (opP->reg == ZPC)
  2391.             nextword |= 0x80;
  2392.         }
  2393.           else if (opP->reg == FAIL)
  2394.         {
  2395.           nextword |= 0x80;
  2396.           tmpreg = 0x30;/* 6.garbage */
  2397.         }
  2398.           else
  2399.         tmpreg = 0x30 + opP->reg - ADDR;    /* 6.areg */
  2400.  
  2401.           siz1 = (opP->con1) ? opP->con1->e_siz : 0;
  2402.           siz2 = (opP->con2) ? opP->con2->e_siz : 0;
  2403.  
  2404.           /* Index register stuff */
  2405.           if (opP->ireg >= DATA + 0 && opP->ireg <= ADDR + 7)
  2406.         {
  2407.           nextword |= (opP->ireg - DATA) << 12;
  2408.  
  2409.           if (opP->isiz == 0 || opP->isiz == 3)
  2410.             nextword |= 0x800;
  2411.           switch (opP->imul)
  2412.             {
  2413.             case 1:
  2414.               break;
  2415.             case 2:
  2416.               nextword |= 0x200;
  2417.               break;
  2418.             case 4:
  2419.               nextword |= 0x400;
  2420.               break;
  2421.             case 8:
  2422.               nextword |= 0x600;
  2423.               break;
  2424.             default:
  2425.               as_fatal ("failed sanity check.");
  2426.             }
  2427.           /* IF its simple,
  2428.              GET US OUT OF HERE! */
  2429.  
  2430.           /* Must be INDEX, with an index
  2431.              register.  Address register
  2432.              cannot be ZERO-PC, and either
  2433.              :b was forced, or we know
  2434.              it will fit */
  2435.           if (opP->mode == AINDX
  2436.               && opP->reg != FAIL
  2437.               && opP->reg != ZPC
  2438.               && (siz1 == 1
  2439.               || (issbyte (baseo)
  2440.                   && !isvar (opP->con1))))
  2441.             {
  2442.               nextword += baseo & 0xff;
  2443.               addword (nextword);
  2444.               if (isvar (opP->con1))
  2445.             add_fix ('B', opP->con1, 0);
  2446.               break;
  2447.             }
  2448.         }
  2449.           else
  2450.         nextword |= 0x40;    /* No index reg */
  2451.  
  2452.           /* It isn't simple.  */
  2453.           nextword |= 0x100;
  2454.           /* If the guy specified a width, we assume that it is
  2455.          wide enough.  Maybe it isn't.  If so, we lose.  */
  2456.           switch (siz1)
  2457.         {
  2458.         case 0:
  2459.           if (isvar (opP->con1) || !issword (baseo))
  2460.             {
  2461.               siz1 = 3;
  2462.               nextword |= 0x30;
  2463.             }
  2464.           else if (baseo == 0)
  2465.             nextword |= 0x10;
  2466.           else
  2467.             {
  2468.               nextword |= 0x20;
  2469.               siz1 = 2;
  2470.             }
  2471.           break;
  2472.         case 1:
  2473.           as_warn ("Byte dispacement won't work.  Defaulting to :w");
  2474.         case 2:
  2475.           nextword |= 0x20;
  2476.           break;
  2477.         case 3:
  2478.           nextword |= 0x30;
  2479.           break;
  2480.         }
  2481.  
  2482.           /* Figure out innner displacement stuff */
  2483.           if (opP->mode != AINDX)
  2484.         {
  2485.           switch (siz2)
  2486.             {
  2487.             case 0:
  2488.               if (isvar (opP->con2) || !issword (outro))
  2489.             {
  2490.               siz2 = 3;
  2491.               nextword |= 0x3;
  2492.             }
  2493.               else if (outro == 0)
  2494.             nextword |= 0x1;
  2495.               else
  2496.             {
  2497.               nextword |= 0x2;
  2498.               siz2 = 2;
  2499.             }
  2500.               break;
  2501.             case 1:
  2502.               as_warn ("Byte dispacement won't work.  Defaulting to :w");
  2503.             case 2:
  2504.               nextword |= 0x2;
  2505.               break;
  2506.             case 3:
  2507.               nextword |= 0x3;
  2508.               break;
  2509.             }
  2510.           if (opP->mode == APODX)
  2511.             nextword |= 0x04;
  2512.           else if (opP->mode == AMIND)
  2513.             nextword |= 0x40;
  2514.         }
  2515.           addword (nextword);
  2516.  
  2517.           if (isvar (opP->con1))
  2518.         {
  2519.           if (opP->reg == PC || opP->reg == ZPC)
  2520.             {
  2521.               opP->con1->e_exp.X_add_number += 6;
  2522.               add_fix (siz1 == 3 ? 'l' : 'w', opP->con1, 1);
  2523.             }
  2524.           else
  2525.             add_fix (siz1 == 3 ? 'l' : 'w', opP->con1, 0);
  2526.         }
  2527.           if (siz1 == 3)
  2528.         addword (baseo >> 16);
  2529.           if (siz1)
  2530.         addword (baseo);
  2531.  
  2532.           if (isvar (opP->con2))
  2533.         {
  2534.           if (opP->reg == PC || opP->reg == ZPC)
  2535.             {
  2536.               opP->con1->e_exp.X_add_number += 6;
  2537.               add_fix (siz2 == 3 ? 'l' : 'w', opP->con2, 1);
  2538.             }
  2539.           else
  2540.             add_fix (siz2 == 3 ? 'l' : 'w', opP->con2, 0);
  2541.         }
  2542.           if (siz2 == 3)
  2543.         addword (outro >> 16);
  2544.           if (siz2)
  2545.         addword (outro);
  2546.  
  2547.           break;
  2548.  
  2549.         case ABSL:
  2550.           nextword = get_num (opP->con1, 80);
  2551.           switch (opP->con1->e_siz)
  2552.         {
  2553.         default:
  2554.           as_warn ("Unknown size for absolute reference");
  2555.         case 0:
  2556.           if (!isvar (opP->con1) && issword (offs (opP->con1)))
  2557.             {
  2558.               tmpreg = 0x38;    /* 7.0 */
  2559.               addword (nextword);
  2560.               break;
  2561.             }
  2562.           /* Don't generate pc relative code on 68010 and
  2563.              68000.  */
  2564.           if (isvar (opP->con1)
  2565.               && !subs (opP->con1)
  2566.               && seg (opP->con1) == text_section
  2567.               && now_seg == text_section
  2568.               && cpu_of_arch (current_architecture) >= m68020
  2569.               && !flag_long_jumps
  2570.               && !strchr ("~%&$?", s[0]))
  2571.             {
  2572.               tmpreg = 0x3A;    /* 7.2 */
  2573.               add_frag (adds (opP->con1),
  2574.                 offs (opP->con1),
  2575.                 TAB (PCREL, SZ_UNDEF));
  2576.               break;
  2577.             }
  2578.         case 3:    /* Fall through into long */
  2579.           if (isvar (opP->con1))
  2580.             add_fix ('l', opP->con1, 0);
  2581.  
  2582.           tmpreg = 0x39;/* 7.1 mode */
  2583.           addword (nextword >> 16);
  2584.           addword (nextword);
  2585.           break;
  2586.  
  2587.         case 2:    /* Word */
  2588.           if (isvar (opP->con1))
  2589.             add_fix ('w', opP->con1, 0);
  2590.  
  2591.           tmpreg = 0x38;/* 7.0 mode */
  2592.           addword (nextword);
  2593.           break;
  2594.         }
  2595.           break;
  2596.         case DINDR:
  2597.           as_bad ("invalid indirect register");
  2598.           break;
  2599.         case MSCR:
  2600.         default:
  2601.           as_bad ("unknown/incorrect operand");
  2602.           /* abort(); */
  2603.         }
  2604.       install_gen_operand (s[1], tmpreg);
  2605.       break;
  2606.  
  2607.     case '#':
  2608.     case '^':
  2609.       switch (s[1])
  2610.         {            /* JF: I hate floating point! */
  2611.         case 'j':
  2612.           tmpreg = 70;
  2613.           break;
  2614.         case '8':
  2615.           tmpreg = 20;
  2616.           break;
  2617.         case 'C':
  2618.           tmpreg = 50;
  2619.           break;
  2620.         case '3':
  2621.         default:
  2622.           tmpreg = 80;
  2623.           break;
  2624.         }
  2625.       tmpreg = get_num (opP->con1, tmpreg);
  2626.       if (isvar (opP->con1))
  2627.         add_fix (s[1], opP->con1, 0);
  2628.       switch (s[1])
  2629.         {
  2630.         case 'b':        /* Danger:  These do no check for
  2631.                    certain types of overflow.
  2632.                    user beware! */
  2633.           if (!isbyte (tmpreg))
  2634.         opP->error = "out of range";
  2635.           insop (tmpreg, opcode);
  2636.           if (isvar (opP->con1))
  2637.         the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2638.           break;
  2639.         case 'w':
  2640.           if (!isword (tmpreg))
  2641.         opP->error = "out of range";
  2642.           insop (tmpreg, opcode);
  2643.           if (isvar (opP->con1))
  2644.         the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2645.           break;
  2646.         case 'l':
  2647.           /* Because of the way insop works, we put these two out
  2648.          backwards.  */
  2649.           insop (tmpreg, opcode);
  2650.           insop (tmpreg >> 16, opcode);
  2651.           if (isvar (opP->con1))
  2652.         the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2653.           break;
  2654.         case '3':
  2655.           tmpreg &= 0xFF;
  2656.         case '8':
  2657.         case 'C':
  2658.           install_operand (s[1], tmpreg);
  2659.           break;
  2660.         default:
  2661.           as_fatal ("Internal error:  Unknown mode #%c in line %d of file \"%s\"", s[1], __LINE__, __FILE__);
  2662.         }
  2663.       break;
  2664.  
  2665.     case '+':
  2666.     case '-':
  2667.     case 'A':
  2668.     case 'a':
  2669.       install_operand (s[1], opP->reg - ADDR);
  2670.       break;
  2671.  
  2672.     case 'B':
  2673.       tmpreg = get_num (opP->con1, 80);
  2674.       switch (s[1])
  2675.         {
  2676.         case 'B':
  2677.           /* Needs no offsetting */
  2678.           add_fix ('B', opP->con1, 1);
  2679.           break;
  2680.         case 'W':
  2681.           /* Offset the displacement to be relative to byte disp location */
  2682.           opP->con1->e_exp.X_add_number += 2;
  2683.           add_fix ('w', opP->con1, 1);
  2684.           addword (0);
  2685.           break;
  2686.         case 'L':
  2687.         long_branch:
  2688.           if (cpu_of_arch (current_architecture) < m68020)    /* 68000 or 010 */
  2689.         as_warn ("Can't use long branches on 68000/68010");
  2690.           the_ins.opcode[the_ins.numo - 1] |= 0xff;
  2691.           /* Offset the displacement to be relative to byte disp location */
  2692.           opP->con1->e_exp.X_add_number += 4;
  2693.           add_fix ('l', opP->con1, 1);
  2694.           addword (0);
  2695.           addword (0);
  2696.           break;
  2697.         case 'g':
  2698.           if (subs (opP->con1))    /* We can't relax it */
  2699.         goto long_branch;
  2700.  
  2701.           /* This could either be a symbol, or an
  2702.          absolute address.  No matter, the
  2703.          frag hacking will finger it out.
  2704.          Not quite: it can't switch from
  2705.          BRANCH to BCC68000 for the case
  2706.          where opnd is absolute (it needs
  2707.          to use the 68000 hack since no
  2708.          conditional abs jumps).  */
  2709.           if (((cpu_of_arch (current_architecture) < m68020) || (0 == adds (opP->con1)))
  2710.           && (the_ins.opcode[0] >= 0x6200)
  2711.           && (the_ins.opcode[0] <= 0x6f00))
  2712.         {
  2713.           add_frag (adds (opP->con1), offs (opP->con1), TAB (BCC68000, SZ_UNDEF));
  2714.         }
  2715.           else
  2716.         {
  2717.           add_frag (adds (opP->con1), offs (opP->con1), TAB (ABRANCH, SZ_UNDEF));
  2718.         }
  2719.           break;
  2720.         case 'w':
  2721.           if (isvar (opP->con1))
  2722.         {
  2723. #if 1
  2724.           /* check for DBcc instruction */
  2725.           if ((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
  2726.             {
  2727.               /* size varies if patch */
  2728.               /* needed for long form */
  2729.               add_frag (adds (opP->con1), offs (opP->con1), TAB (DBCC, SZ_UNDEF));
  2730.               break;
  2731.             }
  2732. #endif
  2733.           /* Don't ask! */
  2734.           opP->con1->e_exp.X_add_number += 2;
  2735.           add_fix ('w', opP->con1, 1);
  2736.         }
  2737.           addword (0);
  2738.           break;
  2739.         case 'C':        /* Fixed size LONG coproc branches */
  2740.           the_ins.opcode[the_ins.numo - 1] |= 0x40;
  2741.           /* Offset the displacement to be relative to byte disp location */
  2742.           /* Coproc branches don't have a byte disp option, but they are
  2743.        compatible with the ordinary branches, which do... */
  2744.           opP->con1->e_exp.X_add_number += 4;
  2745.           add_fix ('l', opP->con1, 1);
  2746.           addword (0);
  2747.           addword (0);
  2748.           break;
  2749.         case 'c':        /* Var size Coprocesssor branches */
  2750.           if (subs (opP->con1))
  2751.         {
  2752.           add_fix ('l', opP->con1, 1);
  2753.           add_frag ((symbolS *) 0, (long) 0, TAB (FBRANCH, LONG));
  2754.         }
  2755.           else if (adds (opP->con1))
  2756.         {
  2757.           add_frag (adds (opP->con1), offs (opP->con1), TAB (FBRANCH, SZ_UNDEF));
  2758.         }
  2759.           else
  2760.         {
  2761.           /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
  2762.           the_ins.opcode[the_ins.numo - 1] |= 0x40;
  2763.           add_fix ('l', opP->con1, 1);
  2764.           addword (0);
  2765.           addword (4);
  2766.         }
  2767.           break;
  2768.         default:
  2769.           as_fatal ("Internal error:  operand type B%c unknown in line %d of file \"%s\"",
  2770.             s[1], __LINE__, __FILE__);
  2771.         }
  2772.       break;
  2773.  
  2774.     case 'C':        /* Ignore it */
  2775.       break;
  2776.  
  2777.     case 'd':        /* JF this is a kludge */
  2778.       if (opP->mode == AOFF)
  2779.         {
  2780.           install_operand ('s', opP->reg - ADDR);
  2781.         }
  2782.       else
  2783.         {
  2784.           char *tmpP;
  2785.  
  2786.           tmpP = opP->con1->e_end - 2;
  2787.           opP->con1->e_beg++;
  2788.           opP->con1->e_end -= 4;    /* point to the , */
  2789.           baseo = m68k_reg_parse (&tmpP);
  2790.           if (baseo < ADDR + 0 || baseo > ADDR + 7)
  2791.         {
  2792.           as_bad ("Unknown address reg, using A0");
  2793.           baseo = 0;
  2794.         }
  2795.           else
  2796.         baseo -= ADDR;
  2797.           install_operand ('s', baseo);
  2798.         }
  2799.       tmpreg = get_num (opP->con1, 80);
  2800.       if (!issword (tmpreg))
  2801.         {
  2802.           as_warn ("Expression out of range, using 0");
  2803.           tmpreg = 0;
  2804.         }
  2805.       addword (tmpreg);
  2806.       break;
  2807.  
  2808.     case 'D':
  2809.       install_operand (s[1], opP->reg - DATA);
  2810.       break;
  2811.  
  2812.     case 'F':
  2813.       install_operand (s[1], opP->reg - FPREG);
  2814.       break;
  2815.  
  2816.     case 'I':
  2817.       tmpreg = 1 + opP->reg - COPNUM;
  2818.       if (tmpreg == 8)
  2819.         tmpreg = 0;
  2820.       install_operand (s[1], tmpreg);
  2821.       break;
  2822.  
  2823.     case 'J':        /* JF foo */
  2824.       switch (opP->reg)
  2825.         {
  2826.         case SFC:
  2827.           tmpreg = 0x000;
  2828.           break;
  2829.         case DFC:
  2830.           tmpreg = 0x001;
  2831.           break;
  2832.         case CACR:
  2833.           tmpreg = 0x002;
  2834.           break;
  2835.         case TC:
  2836.           tmpreg = 0x003;
  2837.           break;
  2838.         case ITT0:
  2839.           tmpreg = 0x004;
  2840.           break;
  2841.         case ITT1:
  2842.           tmpreg = 0x005;
  2843.           break;
  2844.         case DTT0:
  2845.           tmpreg = 0x006;
  2846.           break;
  2847.         case DTT1:
  2848.           tmpreg = 0x007;
  2849.           break;
  2850.  
  2851.         case USP:
  2852.           tmpreg = 0x800;
  2853.           break;
  2854.         case VBR:
  2855.           tmpreg = 0x801;
  2856.           break;
  2857.         case CAAR:
  2858.           tmpreg = 0x802;
  2859.           break;
  2860.         case MSP:
  2861.           tmpreg = 0x803;
  2862.           break;
  2863.         case ISP:
  2864.           tmpreg = 0x804;
  2865.           break;
  2866.         case MMUSR:
  2867.           tmpreg = 0x805;
  2868.           break;
  2869.         case URP:
  2870.           tmpreg = 0x806;
  2871.           break;
  2872.         case SRP:
  2873.           tmpreg = 0x807;
  2874.           break;
  2875.         default:
  2876.           as_fatal ("failed sanity check.");
  2877.         }
  2878.       install_operand (s[1], tmpreg);
  2879.       break;
  2880.  
  2881.     case 'k':
  2882.       tmpreg = get_num (opP->con1, 55);
  2883.       install_operand (s[1], tmpreg & 0x7f);
  2884.       break;
  2885.  
  2886.     case 'l':
  2887.       tmpreg = opP->reg;
  2888.       if (s[1] == 'w')
  2889.         {
  2890.           if (tmpreg & 0x7FF0000)
  2891.         as_bad ("Floating point register in register list");
  2892.           insop (reverse_16_bits (tmpreg), opcode);
  2893.         }
  2894.       else
  2895.         {
  2896.           if (tmpreg & 0x700FFFF)
  2897.         as_bad ("Wrong register in floating-point reglist");
  2898.           install_operand (s[1], reverse_8_bits (tmpreg >> 16));
  2899.         }
  2900.       break;
  2901.  
  2902.     case 'L':
  2903.       tmpreg = opP->reg;
  2904.       if (s[1] == 'w')
  2905.         {
  2906.           if (tmpreg & 0x7FF0000)
  2907.         as_bad ("Floating point register in register list");
  2908.           insop (tmpreg, opcode);
  2909.         }
  2910.       else if (s[1] == '8')
  2911.         {
  2912.           if (tmpreg & 0x0FFFFFF)
  2913.         as_bad ("incorrect register in reglist");
  2914.           install_operand (s[1], tmpreg >> 24);
  2915.         }
  2916.       else
  2917.         {
  2918.           if (tmpreg & 0x700FFFF)
  2919.         as_bad ("wrong register in floating-point reglist");
  2920.           else
  2921.         install_operand (s[1], tmpreg >> 16);
  2922.         }
  2923.       break;
  2924.  
  2925.     case 'M':
  2926.       install_operand (s[1], get_num (opP->con1, 60));
  2927.       break;
  2928.  
  2929.     case 'O':
  2930.       tmpreg = (opP->mode == DREG)
  2931.         ? 0x20 + opP->reg - DATA
  2932.         : (get_num (opP->con1, 40) & 0x1F);
  2933.       install_operand (s[1], tmpreg);
  2934.       break;
  2935.  
  2936.     case 'Q':
  2937.       tmpreg = get_num (opP->con1, 10);
  2938.       if (tmpreg == 8)
  2939.         tmpreg = 0;
  2940.       install_operand (s[1], tmpreg);
  2941.       break;
  2942.  
  2943.     case 'R':
  2944.     case 'r':
  2945.       /* This depends on the fact that ADDR registers are
  2946.      eight more than their corresponding DATA regs, so
  2947.      the result will have the ADDR_REG bit set */
  2948.       install_operand (s[1], opP->reg - DATA);
  2949.       break;
  2950.  
  2951.     case 's':
  2952.       if (opP->reg == FPI)
  2953.         tmpreg = 0x1;
  2954.       else if (opP->reg == FPS)
  2955.         tmpreg = 0x2;
  2956.       else if (opP->reg == FPC)
  2957.         tmpreg = 0x4;
  2958.       else
  2959.         as_fatal ("failed sanity check.");
  2960.       install_operand (s[1], tmpreg);
  2961.       break;
  2962.  
  2963.     case 'S':        /* Ignore it */
  2964.       break;
  2965.  
  2966.     case 'T':
  2967.       install_operand (s[1], get_num (opP->con1, 30));
  2968.       break;
  2969.  
  2970.     case 'U':        /* Ignore it */
  2971.       break;
  2972.  
  2973.     case 'c':
  2974.       switch (opP->reg)
  2975.         {
  2976.         case NC:
  2977.           tmpreg = 0;
  2978.           break;
  2979.         case DC:
  2980.           tmpreg = 1;
  2981.           break;
  2982.         case IC:
  2983.           tmpreg = 2;
  2984.           break;
  2985.         case BC:
  2986.           tmpreg = 3;
  2987.           break;
  2988.         default:
  2989.           as_fatal ("failed sanity check");
  2990.         }            /* switch on cache token */
  2991.       install_operand (s[1], tmpreg);
  2992.       break;
  2993. #ifndef NO_68851
  2994.       /* JF: These are out of order, I fear. */
  2995.     case 'f':
  2996.       switch (opP->reg)
  2997.         {
  2998.         case SFC:
  2999.           tmpreg = 0;
  3000.           break;
  3001.         case DFC:
  3002.           tmpreg = 1;
  3003.           break;
  3004.         default:
  3005.           as_fatal ("failed sanity check.");
  3006.         }
  3007.       install_operand (s[1], tmpreg);
  3008.       break;
  3009.  
  3010.     case 'P':
  3011.       switch (opP->reg)
  3012.         {
  3013.         case TC:
  3014.           tmpreg = 0;
  3015.           break;
  3016.         case CAL:
  3017.           tmpreg = 4;
  3018.           break;
  3019.         case VAL:
  3020.           tmpreg = 5;
  3021.           break;
  3022.         case SCC:
  3023.           tmpreg = 6;
  3024.           break;
  3025.         case AC:
  3026.           tmpreg = 7;
  3027.           break;
  3028.         default:
  3029.           as_fatal ("failed sanity check.");
  3030.         }
  3031.       install_operand (s[1], tmpreg);
  3032.       break;
  3033.  
  3034.     case 'V':
  3035.       if (opP->reg == VAL)
  3036.         break;
  3037.       as_fatal ("failed sanity check.");
  3038.  
  3039.     case 'W':
  3040.       switch (opP->reg)
  3041.         {
  3042.  
  3043.         case DRP:
  3044.           tmpreg = 1;
  3045.           break;
  3046.         case SRP:
  3047.           tmpreg = 2;
  3048.           break;
  3049.         case CRP:
  3050.           tmpreg = 3;
  3051.           break;
  3052.         default:
  3053.           as_fatal ("failed sanity check.");
  3054.         }
  3055.       install_operand (s[1], tmpreg);
  3056.       break;
  3057.  
  3058.     case 'X':
  3059.       switch (opP->reg)
  3060.         {
  3061.         case BAD:
  3062.         case BAD + 1:
  3063.         case BAD + 2:
  3064.         case BAD + 3:
  3065.         case BAD + 4:
  3066.         case BAD + 5:
  3067.         case BAD + 6:
  3068.         case BAD + 7:
  3069.           tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  3070.           break;
  3071.  
  3072.         case BAC:
  3073.         case BAC + 1:
  3074.         case BAC + 2:
  3075.         case BAC + 3:
  3076.         case BAC + 4:
  3077.         case BAC + 5:
  3078.         case BAC + 6:
  3079.         case BAC + 7:
  3080.           tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  3081.           break;
  3082.  
  3083.         default:
  3084.           as_fatal ("failed sanity check.");
  3085.         }
  3086.       install_operand (s[1], tmpreg);
  3087.       break;
  3088.     case 'Y':
  3089.       know (opP->reg == PSR);
  3090.       break;
  3091.     case 'Z':
  3092.       know (opP->reg == PCSR);
  3093.       break;
  3094. #endif /* m68851 */
  3095.     case '3':
  3096.       switch (opP->reg)
  3097.         {
  3098.         case TT0:
  3099.           tmpreg = 2;
  3100.           break;
  3101.         case TT1:
  3102.           tmpreg = 3;
  3103.           break;
  3104.         default:
  3105.           as_fatal ("failed sanity check");
  3106.         }
  3107.       install_operand (s[1], tmpreg);
  3108.       break;
  3109.     case 't':
  3110.       tmpreg = get_num (opP->con1, 20);
  3111.       install_operand (s[1], tmpreg);
  3112.       break;
  3113.     case '_':        /* used only for move16 absolute 32-bit address */
  3114.       tmpreg = get_num (opP->con1, 80);
  3115.       addword (tmpreg >> 16);
  3116.       addword (tmpreg & 0xFFFF);
  3117.       break;
  3118.     default:
  3119.       as_fatal ("Internal error:  Operand type %c unknown in line %d of file \"%s\"",
  3120.             s[0], __LINE__, __FILE__);
  3121.     }
  3122.     }
  3123.  
  3124.   /* By the time whe get here (FINALLY) the_ins contains the complete
  3125.      instruction, ready to be emitted. . . */
  3126. }                /* m68k_ip() */
  3127.  
  3128. /*
  3129.  * get_regs := '/' + ?
  3130.  *    | '-' + <register>
  3131.  *    | '-' + <register> + ?
  3132.  *    | <empty>
  3133.  *    ;
  3134.  *
  3135.  
  3136.  * The idea here must be to scan in a set of registers but I don't
  3137.  * understand it.  Looks awfully sloppy to me but I don't have any doc on
  3138.  * this format so...
  3139.  
  3140.  *
  3141.  *
  3142.  */
  3143.  
  3144. static int
  3145. get_regs (i, str, opP)
  3146.      int i;
  3147.      struct m68k_op *opP;
  3148.      char *str;
  3149. {
  3150.   /*                 26, 25, 24, 23-16,  15-8, 0-7 */
  3151.   /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
  3152.   unsigned long cur_regs = 0;
  3153.   int reg1, reg2;
  3154.  
  3155. #define ADD_REG(x)    {     if(x==FPI) cur_regs|=(1<<24);\
  3156. else if(x==FPS) cur_regs|=(1<<25);\
  3157. else if(x==FPC) cur_regs|=(1<<26);\
  3158. else cur_regs|=(1<<(x-1));  }
  3159.  
  3160.   reg1 = i;
  3161.   for (;;)
  3162.     {
  3163.       if (*str == '/')
  3164.     {
  3165.       ADD_REG (reg1);
  3166.       str++;
  3167.     }
  3168.       else if (*str == '-')
  3169.     {
  3170.       str++;
  3171.       reg2 = m68k_reg_parse (&str);
  3172.       if (reg2 < DATA || reg2 >= FPREG + 8 || reg1 == FPI || reg1 == FPS || reg1 == FPC)
  3173.         {
  3174.           opP->error = "unknown register in register list";
  3175.           return FAIL;
  3176.         }
  3177.       while (reg1 <= reg2)
  3178.         {
  3179.           ADD_REG (reg1);
  3180.           reg1++;
  3181.         }
  3182.       if (*str == '\0')
  3183.         break;
  3184.     }
  3185.       else if (*str == '\0')
  3186.     {
  3187.       ADD_REG (reg1);
  3188.       break;
  3189.     }
  3190.       else
  3191.     {
  3192.       opP->error = "unknow character in register list";
  3193.       return FAIL;
  3194.     }
  3195.       /* DJA -- Bug Fix.  Did't handle d1-d2/a1 until the following instruction was added */
  3196.       if (*str == '/')
  3197.     str++;
  3198.       reg1 = m68k_reg_parse (&str);
  3199.       if ((reg1 < DATA || reg1 >= FPREG + 8) && !(reg1 == FPI || reg1 == FPS || reg1 == FPC))
  3200.     {
  3201.       opP->error = "unknown register in register list";
  3202.       return FAIL;
  3203.     }
  3204.     }
  3205.   opP->reg = cur_regs;
  3206.   return OK;
  3207. }                /* get_regs() */
  3208.  
  3209. static int
  3210. reverse_16_bits (in)
  3211.      int in;
  3212. {
  3213.   int out = 0;
  3214.   int n;
  3215.  
  3216.   static int mask[16] =
  3217.   {
  3218.     0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  3219.     0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
  3220.   };
  3221.   for (n = 0; n < 16; n++)
  3222.     {
  3223.       if (in & mask[n])
  3224.     out |= mask[15 - n];
  3225.     }
  3226.   return out;
  3227. }                /* reverse_16_bits() */
  3228.  
  3229. static int
  3230. reverse_8_bits (in)
  3231.      int in;
  3232. {
  3233.   int out = 0;
  3234.   int n;
  3235.  
  3236.   static int mask[8] =
  3237.   {
  3238.     0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  3239.   };
  3240.  
  3241.   for (n = 0; n < 8; n++)
  3242.     {
  3243.       if (in & mask[n])
  3244.     out |= mask[7 - n];
  3245.     }
  3246.   return out;
  3247. }                /* reverse_8_bits() */
  3248.  
  3249. static void
  3250. install_operand (mode, val)
  3251.      int mode;
  3252.      int val;
  3253. {
  3254.   switch (mode)
  3255.     {
  3256.     case 's':
  3257.       the_ins.opcode[0] |= val & 0xFF;    /* JF FF is for M kludge */
  3258.       break;
  3259.     case 'd':
  3260.       the_ins.opcode[0] |= val << 9;
  3261.       break;
  3262.     case '1':
  3263.       the_ins.opcode[1] |= val << 12;
  3264.       break;
  3265.     case '2':
  3266.       the_ins.opcode[1] |= val << 6;
  3267.       break;
  3268.     case '3':
  3269.       the_ins.opcode[1] |= val;
  3270.       break;
  3271.     case '4':
  3272.       the_ins.opcode[2] |= val << 12;
  3273.       break;
  3274.     case '5':
  3275.       the_ins.opcode[2] |= val << 6;
  3276.       break;
  3277.     case '6':
  3278.       /* DANGER!  This is a hack to force cas2l and cas2w cmds to be
  3279.      three words long! */
  3280.       the_ins.numo++;
  3281.       the_ins.opcode[2] |= val;
  3282.       break;
  3283.     case '7':
  3284.       the_ins.opcode[1] |= val << 7;
  3285.       break;
  3286.     case '8':
  3287.       the_ins.opcode[1] |= val << 10;
  3288.       break;
  3289. #ifndef NO_68851
  3290.     case '9':
  3291.       the_ins.opcode[1] |= val << 5;
  3292.       break;
  3293. #endif
  3294.  
  3295.     case 't':
  3296.       the_ins.opcode[1] |= (val << 10) | (val << 7);
  3297.       break;
  3298.     case 'D':
  3299.       the_ins.opcode[1] |= (val << 12) | val;
  3300.       break;
  3301.     case 'g':
  3302.       the_ins.opcode[0] |= val = 0xff;
  3303.       break;
  3304.     case 'i':
  3305.       the_ins.opcode[0] |= val << 9;
  3306.       break;
  3307.     case 'C':
  3308.       the_ins.opcode[1] |= val;
  3309.       break;
  3310.     case 'j':
  3311.       the_ins.opcode[1] |= val;
  3312.       the_ins.numo++;        /* What a hack */
  3313.       break;
  3314.     case 'k':
  3315.       the_ins.opcode[1] |= val << 4;
  3316.       break;
  3317.     case 'b':
  3318.     case 'w':
  3319.     case 'l':
  3320.       break;
  3321.     case 'e':
  3322.       the_ins.opcode[0] |= (val << 6);
  3323.       break;
  3324.     case 'L':
  3325.       the_ins.opcode[1] = (val >> 16);
  3326.       the_ins.opcode[2] = val & 0xffff;
  3327.       break;
  3328.     case 'c':
  3329.     default:
  3330.       as_fatal ("failed sanity check.");
  3331.     }
  3332. }                /* install_operand() */
  3333.  
  3334. static void
  3335. install_gen_operand (mode, val)
  3336.      int mode;
  3337.      int val;
  3338. {
  3339.   switch (mode)
  3340.     {
  3341.     case 's':
  3342.       the_ins.opcode[0] |= val;
  3343.       break;
  3344.     case 'd':
  3345.       /* This is a kludge!!! */
  3346.       the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
  3347.       break;
  3348.     case 'b':
  3349.     case 'w':
  3350.     case 'l':
  3351.     case 'f':
  3352.     case 'F':
  3353.     case 'x':
  3354.     case 'p':
  3355.       the_ins.opcode[0] |= val;
  3356.       break;
  3357.       /* more stuff goes here */
  3358.     default:
  3359.       as_fatal ("failed sanity check.");
  3360.     }
  3361. }                /* install_gen_operand() */
  3362.  
  3363. /*
  3364.  * verify that we have some number of paren pairs, do m68k_ip_op(), and
  3365.  * then deal with the bitfield hack.
  3366.  */
  3367.  
  3368. static char *
  3369. crack_operand (str, opP)
  3370.      register char *str;
  3371.      register struct m68k_op *opP;
  3372. {
  3373.   register int parens;
  3374.   register int c;
  3375.   register char *beg_str;
  3376.  
  3377.   if (!str)
  3378.     {
  3379.       return str;
  3380.     }
  3381.   beg_str = str;
  3382.   for (parens = 0; *str && (parens > 0 || notend (str)); str++)
  3383.     {
  3384.       if (*str == '(')
  3385.     parens++;
  3386.       else if (*str == ')')
  3387.     {
  3388.       if (!parens)
  3389.         {            /* ERROR */
  3390.           opP->error = "Extra )";
  3391.           return str;
  3392.         }
  3393.       --parens;
  3394.     }
  3395.     }
  3396.   if (!*str && parens)
  3397.     {                /* ERROR */
  3398.       opP->error = "Missing )";
  3399.       return str;
  3400.     }
  3401.   c = *str;
  3402.   *str = '\0';
  3403.   if (m68k_ip_op (beg_str, opP) == FAIL)
  3404.     {
  3405.       *str = c;
  3406.       return str;
  3407.     }
  3408.   *str = c;
  3409.   if (c == '}')
  3410.     c = *++str;            /* JF bitfield hack */
  3411.   if (c)
  3412.     {
  3413.       c = *++str;
  3414.       if (!c)
  3415.     as_bad ("Missing operand");
  3416.     }
  3417.   return str;
  3418. }
  3419.  
  3420. /* See the comment up above where the #define notend(... is */
  3421. #if 0
  3422. notend (s)
  3423.      char *s;
  3424. {
  3425.   if (*s == ',')
  3426.     return 0;
  3427.   if (*s == '{' || *s == '}')
  3428.     return 0;
  3429.   if (*s != ':')
  3430.     return 1;
  3431.   /* This kludge here is for the division cmd, which is a kludge */
  3432.   if (index ("aAdD#", s[1]))
  3433.     return 0;
  3434.   return 1;
  3435. }
  3436.  
  3437. #endif
  3438.  
  3439. /* This is the guts of the machine-dependent assembler.  STR points to a
  3440.    machine dependent instruction.  This function is supposed to emit
  3441.    the frags/bytes it assembles to.
  3442.    */
  3443.  
  3444. void
  3445. insert_reg (regname, regnum)
  3446.      char *regname;
  3447.      int regnum;
  3448. {
  3449.   char buf[100];
  3450.   int i;
  3451.  
  3452. #ifdef REGISTER_PREFIX
  3453.   if (!flag_reg_prefix_optional)
  3454.     {
  3455.       buf[0] = REGISTER_PREFIX;
  3456.       strcpy (buf + 1, regname);
  3457.       regname = buf;
  3458.     }
  3459. #endif
  3460.  
  3461.   symbol_table_insert (symbol_new (regname, reg_section, regnum,
  3462.                    &zero_address_frag));
  3463.  
  3464.   for (i = 0; regname[i]; i++)
  3465.     buf[i] = islower (regname[i]) ? toupper (regname[i]) : regname[i];
  3466.   buf[i] = '\0';
  3467.  
  3468.   symbol_table_insert (symbol_new (buf, reg_section, regnum,
  3469.                    &zero_address_frag));
  3470. }
  3471.  
  3472. struct init_entry
  3473.   {
  3474.     const char *name;
  3475.     int number;
  3476.   };
  3477.  
  3478. static const struct init_entry init_table[] =
  3479. {
  3480.   { "d0", DATA0 },
  3481.   { "d1", DATA1 },
  3482.   { "d2", DATA2 },
  3483.   { "d3", DATA3 },
  3484.   { "d4", DATA4 },
  3485.   { "d5", DATA5 },
  3486.   { "d6", DATA6 },
  3487.   { "d7", DATA7 },
  3488.   { "a0", ADDR0 },
  3489.   { "a1", ADDR1 },
  3490.   { "a2", ADDR2 },
  3491.   { "a3", ADDR3 },
  3492.   { "a4", ADDR4 },
  3493.   { "a5", ADDR5 },
  3494.   { "a6", ADDR6 },
  3495.   { "fp", ADDR6 },
  3496.   { "a7", ADDR7 },
  3497.   { "sp", ADDR7 },
  3498.   { "fp0", FP0 },
  3499.   { "fp1", FP1 },
  3500.   { "fp2", FP2 },
  3501.   { "fp3", FP3 },
  3502.   { "fp4", FP4 },
  3503.   { "fp5", FP5 },
  3504.   { "fp6", FP6 },
  3505.   { "fp7", FP7 },
  3506.   { "fpi", FPI },
  3507.   { "fpiar", FPI },
  3508.   { "fpc", FPI },
  3509.   { "fps", FPS },
  3510.   { "fpsr", FPS },
  3511.   { "fpc", FPC },
  3512.   { "fpcr", FPC },
  3513.  
  3514.   { "cop0", COP0 },
  3515.   { "cop1", COP1 },
  3516.   { "cop2", COP2 },
  3517.   { "cop3", COP3 },
  3518.   { "cop4", COP4 },
  3519.   { "cop5", COP5 },
  3520.   { "cop6", COP6 },
  3521.   { "cop7", COP7 },
  3522.   { "pc", PC },
  3523.   { "zpc", ZPC },
  3524.   { "sr", SR },
  3525.  
  3526.   { "ccr", CCR },
  3527.   { "cc", CCR },
  3528.  
  3529.   { "usp", USP },
  3530.   { "isp", ISP },
  3531.   { "sfc", SFC },
  3532.   { "dfc", DFC },
  3533.   { "cacr", CACR },
  3534.   { "caar", CAAR },
  3535.  
  3536.   { "vbr", VBR },
  3537.  
  3538.   { "msp", MSP },
  3539.   { "itt0", ITT0 },
  3540.   { "itt1", ITT1 },
  3541.   { "dtt0", DTT0 },
  3542.   { "dtt1", DTT1 },
  3543.   { "mmusr", MMUSR },
  3544.   { "tc", TC },
  3545.   { "srp", SRP },
  3546.   { "urp", URP },
  3547.  
  3548.   { "ac", AC },
  3549.   { "bc", BC },
  3550.   { "cal", CAL },
  3551.   { "crp", CRP },
  3552.   { "drp", DRP },
  3553.   { "pcsr", PCSR },
  3554.   { "psr", PSR },
  3555.   { "scc", SCC },
  3556.   { "val", VAL },
  3557.   { "bad0", BAD0 },
  3558.   { "bad1", BAD1 },
  3559.   { "bad2", BAD2 },
  3560.   { "bad3", BAD3 },
  3561.   { "bad4", BAD4 },
  3562.   { "bad5", BAD5 },
  3563.   { "bad6", BAD6 },
  3564.   { "bad7", BAD7 },
  3565.   { "bac0", BAC0 },
  3566.   { "bac1", BAC1 },
  3567.   { "bac2", BAC2 },
  3568.   { "bac3", BAC3 },
  3569.   { "bac4", BAC4 },
  3570.   { "bac5", BAC5 },
  3571.   { "bac6", BAC6 },
  3572.   { "bac7", BAC7 },
  3573.  
  3574.   { "ic", IC },
  3575.   { "dc", DC },
  3576.   { "nc", NC },
  3577.  
  3578.   { "tt0", TT0 },
  3579.   { "tt1", TT1 },
  3580.   /* 68ec030 versions of same */
  3581.   { "ac0", TT0 },
  3582.   { "ac1", TT1 },
  3583.   /* 68ec030 access control unit, identical to 030 MMU status reg */
  3584.   { "acusr", PSR },
  3585.  
  3586.   { 0, 0 }
  3587. };
  3588.  
  3589. void
  3590. init_regtable ()
  3591. {
  3592.   int i;
  3593.   for (i = 0; init_table[i].name; i++)
  3594.     insert_reg (init_table[i].name, init_table[i].number);
  3595. }
  3596.  
  3597. static int no_68851, no_68881;
  3598.  
  3599. #ifdef OBJ_AOUT
  3600. /* a.out machine type.  Default to 68020.  */
  3601. int m68k_aout_machtype = 2;
  3602. #endif
  3603.  
  3604. void
  3605. md_assemble (str)
  3606.      char *str;
  3607. {
  3608.   char *er;
  3609.   short *fromP;
  3610.   char *toP = NULL;
  3611.   int m, n = 0;
  3612.   char *to_beg_P;
  3613.   int shorts_this_frag;
  3614.  
  3615.   memset ((char *) (&the_ins), '\0', sizeof (the_ins));
  3616.   m68k_ip (str);
  3617.   er = the_ins.error;
  3618.   if (!er)
  3619.     {
  3620.       for (n = the_ins.numargs; n; --n)
  3621.     if (the_ins.operands[n].error)
  3622.       {
  3623.         er = the_ins.operands[n].error;
  3624.         break;
  3625.       }
  3626.     }
  3627.   if (er)
  3628.     {
  3629.       as_bad ("%s -- statement `%s' ignored", er, str);
  3630.       return;
  3631.     }
  3632.  
  3633.   if (the_ins.nfrag == 0)
  3634.     {
  3635.       /* No frag hacking involved; just put it out */
  3636.       toP = frag_more (2 * the_ins.numo);
  3637.       fromP = &the_ins.opcode[0];
  3638.       for (m = the_ins.numo; m; --m)
  3639.     {
  3640.       md_number_to_chars (toP, (long) (*fromP), 2);
  3641.       toP += 2;
  3642.       fromP++;
  3643.     }
  3644.       /* put out symbol-dependent info */
  3645.       for (m = 0; m < the_ins.nrel; m++)
  3646.     {
  3647.       switch (the_ins.reloc[m].wid)
  3648.         {
  3649.         case 'B':
  3650.           n = 1;
  3651.           break;
  3652.         case 'b':
  3653.           n = 1;
  3654.           break;
  3655.         case '3':
  3656.           n = 2;
  3657.           break;
  3658.         case 'w':
  3659.           n = 2;
  3660.           break;
  3661.         case 'l':
  3662.           n = 4;
  3663.           break;
  3664.         default:
  3665.           as_fatal ("Don't know how to figure width of %c in md_assemble()",
  3666.             the_ins.reloc[m].wid);
  3667.         }
  3668.  
  3669.       fix_new_exp (frag_now,
  3670.                ((toP - frag_now->fr_literal)
  3671.             - the_ins.numo * 2 + the_ins.reloc[m].n),
  3672.                n,
  3673.                &the_ins.reloc[m].exp,
  3674.                the_ins.reloc[m].pcrel,
  3675.                NO_RELOC);
  3676.     }
  3677.       return;
  3678.     }
  3679.  
  3680.   /* There's some frag hacking */
  3681.   for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
  3682.     {
  3683.       int wid;
  3684.  
  3685.       if (n == 0)
  3686.     wid = 2 * the_ins.fragb[n].fragoff;
  3687.       else
  3688.     wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
  3689.       toP = frag_more (wid);
  3690.       to_beg_P = toP;
  3691.       shorts_this_frag = 0;
  3692.       for (m = wid / 2; m; --m)
  3693.     {
  3694.       md_number_to_chars (toP, (long) (*fromP), 2);
  3695.       toP += 2;
  3696.       fromP++;
  3697.       shorts_this_frag++;
  3698.     }
  3699.       for (m = 0; m < the_ins.nrel; m++)
  3700.     {
  3701.       if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
  3702.         {
  3703.           the_ins.reloc[m].n -= 2 * shorts_this_frag;
  3704.           break;
  3705.         }
  3706.       wid = the_ins.reloc[m].wid;
  3707.       if (wid == 0)
  3708.         continue;
  3709.       the_ins.reloc[m].wid = 0;
  3710.       wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
  3711.  
  3712.       fix_new_exp (frag_now,
  3713.                ((toP - frag_now->fr_literal)
  3714.             - the_ins.numo * 2 + the_ins.reloc[m].n),
  3715.                wid,
  3716.                &the_ins.reloc[m].exp,
  3717.                the_ins.reloc[m].pcrel,
  3718.                NO_RELOC);
  3719.     }
  3720.       (void) frag_var (rs_machine_dependent, 10, 0,
  3721.                (relax_substateT) (the_ins.fragb[n].fragty),
  3722.                the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
  3723.     }
  3724.   n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
  3725.   shorts_this_frag = 0;
  3726.   if (n)
  3727.     {
  3728.       toP = frag_more (n * sizeof (short));
  3729.       while (n--)
  3730.     {
  3731.       md_number_to_chars (toP, (long) (*fromP), 2);
  3732.       toP += 2;
  3733.       fromP++;
  3734.       shorts_this_frag++;
  3735.     }
  3736.     }
  3737.   for (m = 0; m < the_ins.nrel; m++)
  3738.     {
  3739.       int wid;
  3740.  
  3741.       wid = the_ins.reloc[m].wid;
  3742.       if (wid == 0)
  3743.     continue;
  3744.       the_ins.reloc[m].wid = 0;
  3745.       wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
  3746.  
  3747.       fix_new_exp (frag_now,
  3748.            ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
  3749.             - shorts_this_frag * 2),
  3750.            wid,
  3751.            &the_ins.reloc[m].exp,
  3752.            the_ins.reloc[m].pcrel,
  3753.            NO_RELOC);
  3754.     }
  3755. }
  3756.  
  3757. /* See BREAK_UP_BIG_DECL definition, above.  */
  3758. static struct m68k_opcode *
  3759. opcode_ptr (i)
  3760.      int i;
  3761. {
  3762. #ifdef DO_BREAK_UP_BIG_DECL
  3763.   int lim1 = sizeof (m68k_opcodes) / sizeof (m68k_opcodes[0]);
  3764.   if (i >= lim1)
  3765.     return m68k_opcodes_2 + (i - lim1);
  3766. #endif
  3767.   return m68k_opcodes + i;
  3768. }
  3769.  
  3770. void
  3771. md_begin ()
  3772. {
  3773.   /*
  3774.    * md_begin -- set up hash tables with 68000 instructions.
  3775.    * similar to what the vax assembler does.  ---phr
  3776.    */
  3777.   /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  3778.      a copy of it at runtime, adding in the information we want but isn't
  3779.      there.  I think it'd be better to have an awk script hack the table
  3780.      at compile time.  Or even just xstr the table and use it as-is.  But
  3781.      my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
  3782.      names.  */
  3783.  
  3784.   register CONST struct m68k_opcode *ins;
  3785.   register struct m68k_incant *hack, *slak;
  3786.   register const char *retval = 0;    /* empty string, or error msg text */
  3787.   register unsigned int i;
  3788.   register char c;
  3789.  
  3790.   op_hash = hash_new ();
  3791.  
  3792.   obstack_begin (&robyn, 4000);
  3793.   for (i = 0; i < numopcodes; i++)
  3794.     {
  3795.       hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
  3796.       do
  3797.     {
  3798.       ins = opcode_ptr (i);
  3799.       /* We *could* ignore insns that don't match our arch here
  3800.          but just leaving them out of the hash. */
  3801.       slak->m_operands = ins->args;
  3802.       slak->m_opnum = strlen (slak->m_operands) / 2;
  3803.       slak->m_arch = ins->arch;
  3804.       slak->m_opcode = ins->opcode;
  3805.       /* This is kludgey */
  3806.       slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
  3807.       if (i + 1 != numopcodes
  3808.           && !strcmp (ins->name, opcode_ptr (i + 1)->name))
  3809.         {
  3810.           slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
  3811.           i++;
  3812.         }
  3813.       else
  3814.         slak->m_next = 0;
  3815.       slak = slak->m_next;
  3816.     }
  3817.       while (slak);
  3818.  
  3819.       retval = hash_insert (op_hash, ins->name, (char *) hack);
  3820.       if (retval)
  3821.     as_bad ("Internal Error:  Can't hash %s: %s", ins->name, retval);
  3822.     }
  3823.  
  3824.   for (i = 0; i < sizeof (mklower_table); i++)
  3825.     mklower_table[i] = (isupper (c = (char) i)) ? tolower (c) : c;
  3826.  
  3827.   for (i = 0; i < sizeof (notend_table); i++)
  3828.     {
  3829.       notend_table[i] = 0;
  3830.       alt_notend_table[i] = 0;
  3831.     }
  3832.   notend_table[','] = 1;
  3833.   notend_table['{'] = 1;
  3834.   notend_table['}'] = 1;
  3835.   alt_notend_table['a'] = 1;
  3836.   alt_notend_table['A'] = 1;
  3837.   alt_notend_table['d'] = 1;
  3838.   alt_notend_table['D'] = 1;
  3839.   alt_notend_table['#'] = 1;
  3840.   alt_notend_table['f'] = 1;
  3841.   alt_notend_table['F'] = 1;
  3842. #ifdef REGISTER_PREFIX
  3843.   alt_notend_table[REGISTER_PREFIX] = 1;
  3844. #endif
  3845.  
  3846. #ifndef MIT_SYNTAX_ONLY
  3847.   /* Insert pseudo ops, these have to go into the opcode table since
  3848.      gas expects pseudo ops to start with a dot */
  3849.   {
  3850.     int n = 0;
  3851.     while (mote_pseudo_table[n].poc_name)
  3852.       {
  3853.     hack = (struct m68k_incant *)
  3854.       obstack_alloc (&robyn, sizeof (struct m68k_incant));
  3855.     hash_insert (op_hash,
  3856.              mote_pseudo_table[n].poc_name, (char *) hack);
  3857.     hack->m_operands = 0;
  3858.     hack->m_opnum = n;
  3859.     n++;
  3860.       }
  3861.   }
  3862. #endif
  3863.  
  3864.   init_regtable ();
  3865. }
  3866.  
  3867. void
  3868. m68k_init_after_args ()
  3869. {
  3870.   if (cpu_of_arch (current_architecture) == 0)
  3871.     {
  3872.       int cpu_type;
  3873.  
  3874.       if (strcmp (TARGET_CPU, "m68000") == 0
  3875.       || strcmp (TARGET_CPU, "m68302") == 0)
  3876.     cpu_type = m68000;
  3877.       else if (strcmp (TARGET_CPU, "m68010") == 0)
  3878.     cpu_type = m68010;
  3879.       else if (strcmp (TARGET_CPU, "m68020") == 0
  3880.            || strcmp (TARGET_CPU, "m68k") == 0)
  3881.     cpu_type = m68020;
  3882.       else if (strcmp (TARGET_CPU, "m68030") == 0)
  3883.     cpu_type = m68030;
  3884.       else if (strcmp (TARGET_CPU, "m68040") == 0)
  3885.     cpu_type = m68040;
  3886.       else if (strcmp (TARGET_CPU, "m68060") == 0)
  3887.     cpu_type = m68060;
  3888.       else if (strcmp (TARGET_CPU, "cpu32") == 0
  3889.            || strcmp (TARGET_CPU, "m68331") == 0
  3890.            || strcmp (TARGET_CPU, "m68332") == 0
  3891.            || strcmp (TARGET_CPU, "m68333") == 0
  3892.            || strcmp (TARGET_CPU, "m68340") == 0)
  3893.     cpu_type = cpu32;
  3894.       else
  3895.     cpu_type = m68020;
  3896.  
  3897.       current_architecture |= cpu_type;
  3898.     }
  3899. #if 0                /* Could be doing emulation.  */
  3900.   if (current_architecture & m68881)
  3901.     {
  3902.       if (current_architecture & m68000)
  3903.     as_bad ("incompatible processors 68000 and 68881/2 specified");
  3904.       if (current_architecture & m68010)
  3905.     as_bad ("incompatible processors 68010 and 68881/2 specified");
  3906.       if (current_architecture & m68040)
  3907.     as_bad ("incompatible processors 68040 and 68881/2 specified");
  3908.     }
  3909. #endif
  3910.   if (current_architecture & m68851)
  3911.     {
  3912.       if (current_architecture & m68040)
  3913.     {
  3914.       as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
  3915.     }
  3916.     }
  3917.   /* What other incompatibilities could we check for?  */
  3918.  
  3919.   /* Toss in some default assumptions about coprocessors.  */
  3920.   if (!no_68881
  3921.       && (cpu_of_arch (current_architecture)
  3922.       /* Can CPU32 have a 68881 coprocessor??  */
  3923.       & (m68020 | m68030 | cpu32)))
  3924.     {
  3925.       current_architecture |= m68881;
  3926.     }
  3927.   if (!no_68851
  3928.       && (cpu_of_arch (current_architecture) & m68020up) != 0
  3929.       && (cpu_of_arch (current_architecture) & m68040up) == 0)
  3930.     {
  3931.       current_architecture |= m68851;
  3932.     }
  3933.   if (no_68881 && (current_architecture & m68881))
  3934.     as_bad ("options for 68881 and no-68881 both given");
  3935.   if (no_68851 && (current_architecture & m68851))
  3936.     as_bad ("options for 68851 and no-68851 both given");
  3937.  
  3938. #ifdef OBJ_AOUT
  3939.   /* Work out the magic number.  This isn't very general.  */
  3940.   if (current_architecture & m68000)
  3941.     m68k_aout_machtype = 0;
  3942.   else if (current_architecture & m68010)
  3943.     m68k_aout_machtype = 1;
  3944.   else if (current_architecture & m68020)
  3945.     m68k_aout_machtype = 2;
  3946.   else
  3947.     m68k_aout_machtype = 2;
  3948. #endif
  3949.  
  3950.   /* Note which set of "movec" control registers is available.  */
  3951.   switch (cpu_of_arch (current_architecture))
  3952.     {
  3953.     case m68000:
  3954.       control_regs = m68000_control_regs;
  3955.       break;
  3956.     case m68010:
  3957.       control_regs = m68010_control_regs;
  3958.       break;
  3959.     case m68020:
  3960.     case m68030:
  3961.       control_regs = m68020_control_regs;
  3962.       break;
  3963.     case m68040:
  3964.       control_regs = m68040_control_regs;
  3965.       break;
  3966.     case m68060:
  3967.       control_regs = m68060_control_regs;
  3968.       break;
  3969.     default:
  3970.       abort ();
  3971.     }
  3972. }
  3973.  
  3974. #if 0
  3975. #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
  3976.             || (*s == ':' && strchr("aAdD#", s[1]))) \
  3977.            ? 0 : 1)
  3978. #endif
  3979.  
  3980. /* Equal to MAX_PRECISION in atof-ieee.c */
  3981. #define MAX_LITTLENUMS 6
  3982.  
  3983. /* Turn a string in input_line_pointer into a floating point constant of type
  3984.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  3985.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  3986.    */
  3987. char *
  3988. md_atof (type, litP, sizeP)
  3989.      char type;
  3990.      char *litP;
  3991.      int *sizeP;
  3992. {
  3993.   int prec;
  3994.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  3995.   LITTLENUM_TYPE *wordP;
  3996.   char *t;
  3997.   char *atof_ieee ();
  3998.  
  3999.   switch (type)
  4000.     {
  4001.     case 'f':
  4002.     case 'F':
  4003.     case 's':
  4004.     case 'S':
  4005.       prec = 2;
  4006.       break;
  4007.  
  4008.     case 'd':
  4009.     case 'D':
  4010.     case 'r':
  4011.     case 'R':
  4012.       prec = 4;
  4013.       break;
  4014.  
  4015.     case 'x':
  4016.     case 'X':
  4017.       prec = 6;
  4018.       break;
  4019.  
  4020.     case 'p':
  4021.     case 'P':
  4022.       prec = 6;
  4023.       break;
  4024.  
  4025.     default:
  4026.       *sizeP = 0;
  4027.       return "Bad call to MD_ATOF()";
  4028.     }
  4029.   t = atof_ieee (input_line_pointer, type, words);
  4030.   if (t)
  4031.     input_line_pointer = t;
  4032.  
  4033.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  4034.   for (wordP = words; prec--;)
  4035.     {
  4036.       md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
  4037.       litP += sizeof (LITTLENUM_TYPE);
  4038.     }
  4039.   return 0;
  4040. }
  4041.  
  4042. void
  4043. md_number_to_chars (buf, val, n)
  4044.      char *buf;
  4045.      valueT val;
  4046.      int n;
  4047. {
  4048.   number_to_chars_bigendian (buf, val, n);
  4049. }
  4050.  
  4051. static void
  4052. md_apply_fix_2 (fixP, val)
  4053.      fixS *fixP;
  4054.      long val;
  4055. {
  4056.   unsigned long upper_limit;
  4057.   long lower_limit;
  4058.  
  4059.   /* This is unnecessary but it convinces the native rs6000 compiler
  4060.      to generate the code we want.  */
  4061.   char *buf = fixP->fx_frag->fr_literal;
  4062.   buf += fixP->fx_where;
  4063.   /* end ibm compiler workaround */
  4064.  
  4065.   switch (fixP->fx_size)
  4066.     {
  4067.     case 1:
  4068.       *buf++ = val;
  4069.       upper_limit = 0x7f;
  4070.       lower_limit = -0x80;
  4071.       break;
  4072.     case 2:
  4073.       *buf++ = (val >> 8);
  4074.       *buf++ = val;
  4075.       upper_limit = 0x7fff;
  4076.       lower_limit = -0x8000;
  4077.       break;
  4078.     case 4:
  4079.       *buf++ = (val >> 24);
  4080.       *buf++ = (val >> 16);
  4081.       *buf++ = (val >> 8);
  4082.       *buf++ = val;
  4083.       upper_limit = 0x7fffffff;
  4084.       lower_limit = -0x80000000;
  4085.       break;
  4086.     default:
  4087.       BAD_CASE (fixP->fx_size);
  4088.     }
  4089.  
  4090.   /* For non-pc-relative values, it's conceivable we might get something
  4091.      like "0xff" for a byte field.  So extend the upper part of the range
  4092.      to accept such numbers.  We arbitrarily disallow "-0xff" or "0xff+0xff",
  4093.      so that we can do any range checking at all.  */
  4094.   if (!fixP->fx_pcrel)
  4095.     upper_limit = upper_limit * 2 + 1;
  4096.  
  4097.   if ((unsigned) val > upper_limit && (val > 0 || val < lower_limit))
  4098.     as_bad_where (fixP->fx_file, fixP->fx_line, "value out of range");
  4099.  
  4100.   /* A one byte PC-relative reloc means a short branch.  We can't use
  4101.      a short branch with a value of 0 or -1, because those indicate
  4102.      different opcodes (branches with longer offsets).  */
  4103.   if (fixP->fx_pcrel
  4104.       && fixP->fx_size == 1
  4105.       && (fixP->fx_addsy == NULL
  4106.       || S_IS_DEFINED (fixP->fx_addsy))
  4107.       && (val == 0 || val == -1))
  4108.     as_bad_where (fixP->fx_file, fixP->fx_line, "invalid byte branch offset");
  4109. }
  4110.  
  4111. #ifdef BFD_ASSEMBLER
  4112. int
  4113. md_apply_fix (fixP, valp)
  4114.      fixS *fixP;
  4115.      long *valp;
  4116. {
  4117.   md_apply_fix_2 (fixP, *valp);
  4118.   return 1;
  4119. }
  4120. #else
  4121. void md_apply_fix (fixP, val)
  4122.      fixS *fixP;
  4123.      long val;
  4124. {
  4125.   md_apply_fix_2 (fixP, val);
  4126. }
  4127. #endif
  4128.  
  4129. /* *fragP has been relaxed to its final size, and now needs to have
  4130.    the bytes inside it modified to conform to the new size  There is UGLY
  4131.    MAGIC here. ..
  4132.    */
  4133. void
  4134. md_convert_frag_1 (fragP)
  4135.      register fragS *fragP;
  4136. {
  4137.   long disp;
  4138.   long ext = 0;
  4139.  
  4140.   /* Address in object code of the displacement.  */
  4141.   register int object_address = fragP->fr_fix + fragP->fr_address;
  4142.  
  4143.   /* Address in gas core of the place to store the displacement.  */
  4144.   /* This convinces the native rs6000 compiler to generate the code we
  4145.      want. */
  4146.   register char *buffer_address = fragP->fr_literal;
  4147.   buffer_address += fragP->fr_fix;
  4148.   /* end ibm compiler workaround */
  4149.  
  4150.   /* The displacement of the address, from current location.  */
  4151.   disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
  4152.   disp = (disp + fragP->fr_offset) - object_address;
  4153.  
  4154.   switch (fragP->fr_subtype)
  4155.     {
  4156.     case TAB (BCC68000, BYTE):
  4157.     case TAB (ABRANCH, BYTE):
  4158.       know (issbyte (disp));
  4159.       if (disp == 0)
  4160.     as_bad ("short branch with zero offset: use :w");
  4161.       fragP->fr_opcode[1] = disp;
  4162.       ext = 0;
  4163.       break;
  4164.     case TAB (DBCC, SHORT):
  4165.       know (issword (disp));
  4166.       ext = 2;
  4167.       break;
  4168.     case TAB (BCC68000, SHORT):
  4169.     case TAB (ABRANCH, SHORT):
  4170.       know (issword (disp));
  4171.       fragP->fr_opcode[1] = 0x00;
  4172.       ext = 2;
  4173.       break;
  4174.     case TAB (ABRANCH, LONG):
  4175.       if (cpu_of_arch (current_architecture) < m68020)
  4176.     {
  4177.       if (fragP->fr_opcode[0] == 0x61)
  4178.         {
  4179.           fragP->fr_opcode[0] = 0x4E;
  4180.           fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
  4181.           subseg_change (text_section, 0); /* @@ */
  4182.  
  4183.           fix_new (fragP,
  4184.                fragP->fr_fix,
  4185.                4,
  4186.                fragP->fr_symbol,
  4187.                fragP->fr_offset,
  4188.                0,
  4189.                NO_RELOC);
  4190.  
  4191.           fragP->fr_fix += 4;
  4192.           ext = 0;
  4193.         }
  4194.       else if (fragP->fr_opcode[0] == 0x60)
  4195.         {
  4196.           fragP->fr_opcode[0] = 0x4E;
  4197.           fragP->fr_opcode[1] = (char) 0xF9; /* JMP  with ABSL LONG offset */
  4198.           subseg_change (text_section, 0); /* @@ */
  4199.           fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4200.                fragP->fr_offset, 0, NO_RELOC);
  4201.           fragP->fr_fix += 4;
  4202.           ext = 0;
  4203.         }
  4204.       else
  4205.         {
  4206.           as_bad ("Long branch offset not supported.");
  4207.         }
  4208.     }
  4209.       else
  4210.     {
  4211.       fragP->fr_opcode[1] = (char) 0xff;
  4212.       ext = 4;
  4213.     }
  4214.       break;
  4215.     case TAB (BCC68000, LONG):
  4216.       /* only Bcc 68000 instructions can come here */
  4217.       /* change bcc into b!cc/jmp absl long */
  4218.       fragP->fr_opcode[0] ^= 0x01;    /* invert bcc */
  4219.       fragP->fr_opcode[1] = 0x6;/* branch offset = 6 */
  4220.  
  4221.       /* JF: these used to be fr_opcode[2,3], but they may be in a
  4222.        different frag, in which case refering to them is a no-no.
  4223.        Only fr_opcode[0,1] are guaranteed to work. */
  4224.       *buffer_address++ = 0x4e;    /* put in jmp long (0x4ef9) */
  4225.       *buffer_address++ = (char) 0xf9;
  4226.       fragP->fr_fix += 2;    /* account for jmp instruction */
  4227.       subseg_change (text_section, 0);
  4228.       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4229.            fragP->fr_offset, 0, NO_RELOC);
  4230.       fragP->fr_fix += 4;
  4231.       ext = 0;
  4232.       break;
  4233.     case TAB (DBCC, LONG):
  4234.       /* only DBcc 68000 instructions can come here */
  4235.       /* change dbcc into dbcc/jmp absl long */
  4236.       /* JF: these used to be fr_opcode[2-7], but that's wrong */
  4237.       *buffer_address++ = 0x00;    /* branch offset = 4 */
  4238.       *buffer_address++ = 0x04;
  4239.       *buffer_address++ = 0x60;    /* put in bra pc+6 */
  4240.       *buffer_address++ = 0x06;
  4241.       *buffer_address++ = 0x4e;    /* put in jmp long (0x4ef9) */
  4242.       *buffer_address++ = (char) 0xf9;
  4243.  
  4244.       fragP->fr_fix += 6;    /* account for bra/jmp instructions */
  4245.       subseg_change (text_section, 0);
  4246.       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4247.            fragP->fr_offset, 0, NO_RELOC);
  4248.       fragP->fr_fix += 4;
  4249.       ext = 0;
  4250.       break;
  4251.     case TAB (FBRANCH, SHORT):
  4252.       know ((fragP->fr_opcode[1] & 0x40) == 0);
  4253.       ext = 2;
  4254.       break;
  4255.     case TAB (FBRANCH, LONG):
  4256.       fragP->fr_opcode[1] |= 0x40;    /* Turn on LONG bit */
  4257.       ext = 4;
  4258.       break;
  4259.     case TAB (PCREL, SHORT):
  4260.       ext = 2;
  4261.       break;
  4262.     case TAB (PCREL, LONG):
  4263.       /* The thing to do here is force it to ABSOLUTE LONG, since
  4264.     PCREL is really trying to shorten an ABSOLUTE address anyway */
  4265.       /* JF FOO This code has not been tested */
  4266.       subseg_change (text_section, 0);
  4267.       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
  4268.            0, NO_RELOC);
  4269.       if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  4270.     as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
  4271.         (unsigned) fragP->fr_opcode[0],
  4272.         (unsigned long) fragP->fr_address);
  4273.       fragP->fr_opcode[1] &= ~0x3F;
  4274.       fragP->fr_opcode[1] |= 0x39;    /* Mode 7.1 */
  4275.       fragP->fr_fix += 4;
  4276.       ext = 0;
  4277.       break;
  4278.     case TAB (PCLEA, SHORT):
  4279.       subseg_change (text_section, 0);
  4280.       fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
  4281.            fragP->fr_offset, 1, NO_RELOC);
  4282.       fragP->fr_opcode[1] &= ~0x3F;
  4283.       fragP->fr_opcode[1] |= 0x3A;
  4284.       ext = 2;
  4285.       break;
  4286.     case TAB (PCLEA, LONG):
  4287.       subseg_change (text_section, 0);
  4288.       fix_new (fragP, (int) (fragP->fr_fix) + 2, 4, fragP->fr_symbol,
  4289.            fragP->fr_offset + 2, 1, NO_RELOC);
  4290.       *buffer_address++ = 0x01;
  4291.       *buffer_address++ = 0x70;
  4292.       fragP->fr_fix += 2;
  4293.       ext = 4;
  4294.       break;
  4295.     }
  4296.  
  4297.   if (ext)
  4298.     {
  4299.       md_number_to_chars (buffer_address, (long) disp, (int) ext);
  4300.       fragP->fr_fix += ext;
  4301.     }
  4302. }
  4303.  
  4304. #ifndef BFD_ASSEMBLER
  4305.  
  4306. void
  4307. md_convert_frag (headers, fragP)
  4308.      object_headers *headers;
  4309.      fragS *fragP;
  4310. {
  4311.   md_convert_frag_1 (fragP);
  4312. }
  4313.  
  4314. #else
  4315.  
  4316. void
  4317. md_convert_frag (abfd, sec, fragP)
  4318.      bfd *abfd;
  4319.      asection sec;
  4320.      fragS *fragP;
  4321. {
  4322.   md_convert_frag_1 (fragP);
  4323. }
  4324. #endif
  4325.  
  4326. /* Force truly undefined symbols to their maximum size, and generally set up
  4327.    the frag list to be relaxed
  4328.    */
  4329. int
  4330. md_estimate_size_before_relax (fragP, segment)
  4331.      register fragS *fragP;
  4332.      segT segment;
  4333. {
  4334.   int old_fix;
  4335.   register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
  4336.  
  4337.   old_fix = fragP->fr_fix;
  4338.  
  4339.   /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  4340.   switch (fragP->fr_subtype)
  4341.     {
  4342.  
  4343.     case TAB (ABRANCH, SZ_UNDEF):
  4344.       {
  4345.     if ((fragP->fr_symbol != NULL)    /* Not absolute */
  4346.         && S_GET_SEGMENT (fragP->fr_symbol) == segment)
  4347.       {
  4348.         fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
  4349.         break;
  4350.       }
  4351.     else if ((fragP->fr_symbol == 0) || (cpu_of_arch (current_architecture) < m68020))
  4352.       {
  4353.         /* On 68000, or for absolute value, switch to abs long */
  4354.         /* FIXME, we should check abs val, pick short or long */
  4355.         if (fragP->fr_opcode[0] == 0x61)
  4356.           {
  4357.         fragP->fr_opcode[0] = 0x4E;
  4358.         fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
  4359.         subseg_change (text_section, 0);
  4360.         fix_new (fragP, fragP->fr_fix, 4,
  4361.              fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC);
  4362.         fragP->fr_fix += 4;
  4363.         frag_wane (fragP);
  4364.           }
  4365.         else if (fragP->fr_opcode[0] == 0x60)
  4366.           {
  4367.         fragP->fr_opcode[0] = 0x4E;
  4368.         fragP->fr_opcode[1] = (char) 0xF9; /* JMP  with ABSL LONG offset */
  4369.         subseg_change (text_section, 0);
  4370.         fix_new (fragP, fragP->fr_fix, 4,
  4371.              fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC);
  4372.         fragP->fr_fix += 4;
  4373.         frag_wane (fragP);
  4374.           }
  4375.         else
  4376.           {
  4377.         as_warn ("Long branch offset to extern symbol not supported.");
  4378.           }
  4379.       }
  4380.     else
  4381.       {            /* Symbol is still undefined.  Make it simple */
  4382.         fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
  4383.              fragP->fr_offset + 4, 1, NO_RELOC);
  4384.         fragP->fr_fix += 4;
  4385.         fragP->fr_opcode[1] = (char) 0xff;
  4386.         frag_wane (fragP);
  4387.         break;
  4388.       }
  4389.  
  4390.     break;
  4391.       }                /* case TAB(ABRANCH,SZ_UNDEF) */
  4392.  
  4393.     case TAB (FBRANCH, SZ_UNDEF):
  4394.       {
  4395.     if (S_GET_SEGMENT (fragP->fr_symbol) == segment || flag_short_refs)
  4396.       {
  4397.         fragP->fr_subtype = TAB (FBRANCH, SHORT);
  4398.         fragP->fr_var += 2;
  4399.       }
  4400.     else
  4401.       {
  4402.         fragP->fr_subtype = TAB (FBRANCH, LONG);
  4403.         fragP->fr_var += 4;
  4404.       }
  4405.     break;
  4406.       }                /* TAB(FBRANCH,SZ_UNDEF) */
  4407.  
  4408.     case TAB (PCREL, SZ_UNDEF):
  4409.       {
  4410.     if (S_GET_SEGMENT (fragP->fr_symbol) == segment || flag_short_refs)
  4411.       {
  4412.         fragP->fr_subtype = TAB (PCREL, SHORT);
  4413.         fragP->fr_var += 2;
  4414.       }
  4415.     else
  4416.       {
  4417.         fragP->fr_subtype = TAB (PCREL, LONG);
  4418.         fragP->fr_var += 4;
  4419.       }
  4420.     break;
  4421.       }                /* TAB(PCREL,SZ_UNDEF) */
  4422.  
  4423.     case TAB (BCC68000, SZ_UNDEF):
  4424.       {
  4425.     if ((fragP->fr_symbol != NULL)
  4426.         && S_GET_SEGMENT (fragP->fr_symbol) == segment)
  4427.       {
  4428.         fragP->fr_subtype = TAB (BCC68000, BYTE);
  4429.         break;
  4430.       }
  4431.     /* only Bcc 68000 instructions can come here */
  4432.     /* change bcc into b!cc/jmp absl long */
  4433.     fragP->fr_opcode[0] ^= 0x01;    /* invert bcc */
  4434.     if (flag_short_refs)
  4435.       {
  4436.         fragP->fr_opcode[1] = 0x04;    /* branch offset = 6 */
  4437.         /* JF: these were fr_opcode[2,3] */
  4438.         buffer_address[0] = 0x4e;    /* put in jmp long (0x4ef9) */
  4439.         buffer_address[1] = (char) 0xf8;
  4440.         fragP->fr_fix += 2;    /* account for jmp instruction */
  4441.         subseg_change (text_section, 0);
  4442.         fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
  4443.              fragP->fr_offset, 0, NO_RELOC);
  4444.         fragP->fr_fix += 2;
  4445.       }
  4446.     else
  4447.       {
  4448.         fragP->fr_opcode[1] = 0x06;    /* branch offset = 6 */
  4449.         /* JF: these were fr_opcode[2,3] */
  4450.         buffer_address[0] = 0x4e;    /* put in jmp long (0x4ef9) */
  4451.         buffer_address[1] = (char) 0xf9;
  4452.         fragP->fr_fix += 2;    /* account for jmp instruction */
  4453.         subseg_change (text_section, 0);
  4454.         fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4455.              fragP->fr_offset, 0, NO_RELOC);
  4456.         fragP->fr_fix += 4;
  4457.       }
  4458.     frag_wane (fragP);
  4459.     break;
  4460.       }                /* case TAB(BCC68000,SZ_UNDEF) */
  4461.  
  4462.     case TAB (DBCC, SZ_UNDEF):
  4463.       {
  4464.     if (fragP->fr_symbol != NULL && S_GET_SEGMENT (fragP->fr_symbol) == segment)
  4465.       {
  4466.         fragP->fr_subtype = TAB (DBCC, SHORT);
  4467.         fragP->fr_var += 2;
  4468.         break;
  4469.       }
  4470.     /* only DBcc 68000 instructions can come here */
  4471.     /* change dbcc into dbcc/jmp absl long */
  4472.     /* JF: these used to be fr_opcode[2-4], which is wrong. */
  4473.     buffer_address[0] = 0x00;    /* branch offset = 4 */
  4474.     buffer_address[1] = 0x04;
  4475.     buffer_address[2] = 0x60;    /* put in bra pc + ... */
  4476.  
  4477.     if (flag_short_refs)
  4478.       {
  4479.         /* JF: these were fr_opcode[5-7] */
  4480.         buffer_address[3] = 0x04;    /* plus 4 */
  4481.         buffer_address[4] = 0x4e;    /* Put in Jump Word */
  4482.         buffer_address[5] = (char) 0xf8;
  4483.         fragP->fr_fix += 6;    /* account for bra/jmp instruction */
  4484.         subseg_change (text_section, 0);
  4485.         fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
  4486.              fragP->fr_offset, 0, NO_RELOC);
  4487.         fragP->fr_fix += 2;
  4488.       }
  4489.     else
  4490.       {
  4491.         /* JF: these were fr_opcode[5-7] */
  4492.         buffer_address[3] = 0x06;    /* Plus 6 */
  4493.         buffer_address[4] = 0x4e;    /* put in jmp long (0x4ef9) */
  4494.         buffer_address[5] = (char) 0xf9;
  4495.         fragP->fr_fix += 6;    /* account for bra/jmp instruction */
  4496.         subseg_change (text_section, 0);
  4497.         fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4498.              fragP->fr_offset, 0, NO_RELOC);
  4499.         fragP->fr_fix += 4;
  4500.       }
  4501.  
  4502.     frag_wane (fragP);
  4503.     break;
  4504.       }                /* case TAB(DBCC,SZ_UNDEF) */
  4505.  
  4506.     case TAB (PCLEA, SZ_UNDEF):
  4507.       {
  4508.     if ((S_GET_SEGMENT (fragP->fr_symbol)) == segment || flag_short_refs)
  4509.       {
  4510.         fragP->fr_subtype = TAB (PCLEA, SHORT);
  4511.         fragP->fr_var += 2;
  4512.       }
  4513.     else
  4514.       {
  4515.         fragP->fr_subtype = TAB (PCLEA, LONG);
  4516.         fragP->fr_var += 6;
  4517.       }
  4518.     break;
  4519.       }                /* TAB(PCLEA,SZ_UNDEF) */
  4520.  
  4521.     default:
  4522.       break;
  4523.  
  4524.     }                /* switch on subtype looking for SZ_UNDEF's. */
  4525.  
  4526.   /* now that SZ_UNDEF are taken care of, check others */
  4527.   switch (fragP->fr_subtype)
  4528.     {
  4529.     case TAB (BCC68000, BYTE):
  4530.     case TAB (ABRANCH, BYTE):
  4531.       /* We can't do a short jump to the next instruction,
  4532.        so we force word mode.  */
  4533.       if (fragP->fr_symbol && S_GET_VALUE (fragP->fr_symbol) == 0 &&
  4534.       fragP->fr_symbol->sy_frag == fragP->fr_next)
  4535.     {
  4536.       fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
  4537.       fragP->fr_var += 2;
  4538.     }
  4539.       break;
  4540.     default:
  4541.       break;
  4542.     }
  4543.   return fragP->fr_var + fragP->fr_fix - old_fix;
  4544. }
  4545.  
  4546. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  4547. /* the bit-field entries in the relocation_info struct plays hell
  4548.    with the byte-order problems of cross-assembly.  So as a hack,
  4549.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  4550.    you there. -KWK */
  4551. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  4552.    are symbolnum, most sig. byte first.  Last byte is broken up with
  4553.    bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  4554.    nibble as nuthin. (on Sun 3 at least) */
  4555. /* Translate the internal relocation information into target-specific
  4556.    format. */
  4557. #ifdef comment
  4558. void
  4559. md_ri_to_chars (the_bytes, ri)
  4560.      char *the_bytes;
  4561.      struct reloc_info_generic *ri;
  4562. {
  4563.   /* this is easy */
  4564.   md_number_to_chars (the_bytes, ri->r_address, 4);
  4565.   /* now the fun stuff */
  4566.   the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
  4567.   the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
  4568.   the_bytes[6] = ri->r_symbolnum & 0x0ff;
  4569.   the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
  4570.           ((ri->r_extern << 4) & 0x10));
  4571. }
  4572.  
  4573. #endif /* comment */
  4574.  
  4575. #ifndef BFD_ASSEMBLER
  4576. void
  4577. tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
  4578.      char *where;
  4579.      fixS *fixP;
  4580.      relax_addressT segment_address_in_file;
  4581. {
  4582.   /*
  4583.    * In: length of relocation (or of address) in chars: 1, 2 or 4.
  4584.    * Out: GNU LD relocation length code: 0, 1, or 2.
  4585.    */
  4586.  
  4587.   static CONST unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
  4588.   long r_symbolnum;
  4589.  
  4590.   know (fixP->fx_addsy != NULL);
  4591.  
  4592.   md_number_to_chars (where,
  4593.        fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
  4594.               4);
  4595.  
  4596.   r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
  4597.          ? S_GET_TYPE (fixP->fx_addsy)
  4598.          : fixP->fx_addsy->sy_number);
  4599.  
  4600.   where[4] = (r_symbolnum >> 16) & 0x0ff;
  4601.   where[5] = (r_symbolnum >> 8) & 0x0ff;
  4602.   where[6] = r_symbolnum & 0x0ff;
  4603.   where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
  4604.           (((!S_IS_DEFINED (fixP->fx_addsy)) << 4) & 0x10));
  4605. }
  4606. #endif
  4607.  
  4608. #endif /* OBJ_AOUT or OBJ_BOUT */
  4609.  
  4610. #ifndef WORKING_DOT_WORD
  4611. CONST int md_short_jump_size = 4;
  4612. CONST int md_long_jump_size = 6;
  4613.  
  4614. void
  4615. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  4616.      char *ptr;
  4617.      addressT from_addr, to_addr;
  4618.      fragS *frag;
  4619.      symbolS *to_symbol;
  4620. {
  4621.   valueT offset;
  4622.  
  4623.   offset = to_addr - (from_addr + 2);
  4624.  
  4625.   md_number_to_chars (ptr, (valueT) 0x6000, 2);
  4626.   md_number_to_chars (ptr + 2, (valueT) offset, 2);
  4627. }
  4628.  
  4629. void
  4630. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  4631.      char *ptr;
  4632.      addressT from_addr, to_addr;
  4633.      fragS *frag;
  4634.      symbolS *to_symbol;
  4635. {
  4636.   valueT offset;
  4637.  
  4638.   if (cpu_of_arch (current_architecture) < m68020)
  4639.     {
  4640.       offset = to_addr - S_GET_VALUE (to_symbol);
  4641.       md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
  4642.       md_number_to_chars (ptr + 2, (valueT) offset, 4);
  4643.       fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
  4644.            0, NO_RELOC);
  4645.     }
  4646.   else
  4647.     {
  4648.       offset = to_addr - (from_addr + 2);
  4649.       md_number_to_chars (ptr, (valueT) 0x60ff, 2);
  4650.       md_number_to_chars (ptr + 2, (valueT) offset, 4);
  4651.     }
  4652. }
  4653.  
  4654. #endif
  4655. /* Different values of OK tell what its OK to return.  Things that aren't OK are an error (what a shock, no?)
  4656.  
  4657.    0:  Everything is OK
  4658.    10:  Absolute 1:8    only
  4659.    20:  Absolute 0:7    only
  4660.    30:  absolute 0:15    only
  4661.    40:  Absolute 0:31    only
  4662.    50:  absolute 0:127    only
  4663.    55:  absolute -64:63    only
  4664.    60:  absolute -128:127    only
  4665.    70:  absolute 0:4095    only
  4666.    80:  No bignums
  4667.  
  4668.    */
  4669.  
  4670. static int
  4671. get_num (exp, ok)
  4672.      struct m68k_exp *exp;
  4673.      int ok;
  4674. {
  4675. #ifdef TEST2
  4676.   long l = 0;
  4677.  
  4678.   if (!exp->e_beg)
  4679.     return 0;
  4680.   if (*exp->e_beg == '0')
  4681.     {
  4682.       if (exp->e_beg[1] == 'x')
  4683.     sscanf (exp->e_beg + 2, "%x", &l);
  4684.       else
  4685.     sscanf (exp->e_beg + 1, "%O", &l);
  4686.       return l;
  4687.     }
  4688.   return atol (exp->e_beg);
  4689. #else
  4690.   char *save_in;
  4691.   char c_save;
  4692.   segT section;
  4693.  
  4694.   if (!exp)
  4695.     {
  4696.       /* Can't do anything */
  4697.       return 0;
  4698.     }
  4699.   if (!exp->e_beg || !exp->e_end)
  4700.     {
  4701.       seg (exp) = absolute_section;
  4702.       adds (exp) = 0;
  4703.       subs (exp) = 0;
  4704.       offs (exp) = (ok == 10) ? 1 : 0;
  4705.       as_warn ("Null expression defaults to %ld", offs (exp));
  4706.       return 0;
  4707.     }
  4708.  
  4709.   exp->e_siz = 0;
  4710.   if ( /* ok!=80 && */ (exp->e_end[-1] == ':' || exp->e_end[-1] == '.')
  4711.       && (exp->e_end - exp->e_beg) >= 2)
  4712.     {
  4713.       switch (exp->e_end[0])
  4714.     {
  4715.     case 's':
  4716.     case 'S':
  4717.     case 'b':
  4718.     case 'B':
  4719.       exp->e_siz = 1;
  4720.       exp->e_end -= 2;
  4721.       break;
  4722.     case 'w':
  4723.     case 'W':
  4724.       exp->e_siz = 2;
  4725.       exp->e_end -= 2;
  4726.       break;
  4727.     case 'l':
  4728.     case 'L':
  4729.       exp->e_siz = 3;
  4730.       exp->e_end -= 2;
  4731.       break;
  4732.     default:
  4733.       if (exp->e_end[-1] == ':')
  4734.         as_bad ("Unknown size for expression \"%c\"", exp->e_end[0]);
  4735.       break;
  4736.     }
  4737.     }
  4738.   c_save = exp->e_end[1];
  4739.   exp->e_end[1] = '\0';
  4740.   save_in = input_line_pointer;
  4741.   input_line_pointer = exp->e_beg;
  4742.   section = expression (&exp->e_exp);
  4743.   seg (exp) = section;
  4744.   if (exp->e_exp.X_op == O_absent)
  4745.     {
  4746.       /* Do the same thing the VAX asm does */
  4747.       seg (exp) = absolute_section;
  4748.       op (exp) = O_constant;
  4749.       adds (exp) = 0;
  4750.       subs (exp) = 0;
  4751.       offs (exp) = 0;
  4752.       if (ok == 10)
  4753.     {
  4754.       as_warn ("expression out of range: defaulting to 1");
  4755.       offs (exp) = 1;
  4756.     }
  4757.     }
  4758.   else if (exp->e_exp.X_op == O_constant)
  4759.     {
  4760.       switch (ok)
  4761.     {
  4762.     case 10:
  4763.       if (offs (exp) < 1 || offs (exp) > 8)
  4764.         {
  4765.           as_warn ("expression out of range: defaulting to 1");
  4766.           offs (exp) = 1;
  4767.         }
  4768.       break;
  4769.     case 20:
  4770.       if (offs (exp) < 0 || offs (exp) > 7)
  4771.         goto outrange;
  4772.       break;
  4773.     case 30:
  4774.       if (offs (exp) < 0 || offs (exp) > 15)
  4775.         goto outrange;
  4776.       break;
  4777.     case 40:
  4778.       if (offs (exp) < 0 || offs (exp) > 32)
  4779.         goto outrange;
  4780.       break;
  4781.     case 50:
  4782.       if (offs (exp) < 0 || offs (exp) > 127)
  4783.         goto outrange;
  4784.       break;
  4785.     case 55:
  4786.       if (offs (exp) < -64 || offs (exp) > 63)
  4787.         goto outrange;
  4788.       break;
  4789.     case 60:
  4790.       if (offs (exp) < -128 || offs (exp) > 127)
  4791.         goto outrange;
  4792.       break;
  4793.     case 70:
  4794.       if (offs (exp) < 0 || offs (exp) > 4095)
  4795.         {
  4796.         outrange:
  4797.           as_warn ("expression out of range: defaulting to 0");
  4798.           offs (exp) = 0;
  4799.         }
  4800.       break;
  4801.     default:
  4802.       break;
  4803.     }
  4804.     }
  4805.   else if (exp->e_exp.X_op == O_big)
  4806.     {
  4807.       if (offs (exp) <= 0    /* flonum */
  4808.       && (ok == 80        /* no bignums */
  4809.           || (ok > 10    /* small-int ranges including 0 ok */
  4810.           /* If we have a flonum zero, a zero integer should
  4811.              do as well (e.g., in moveq).  */
  4812.           && generic_floating_point_number.exponent == 0
  4813.           && generic_floating_point_number.low[0] == 0)))
  4814.     {
  4815.       /* HACK! Turn it into a long */
  4816.       LITTLENUM_TYPE words[6];
  4817.  
  4818.       gen_to_words (words, 2, 8L);    /* These numbers are magic! */
  4819.       seg (exp) = absolute_section;
  4820.       op (exp) = O_constant;
  4821.       adds (exp) = 0;
  4822.       subs (exp) = 0;
  4823.       offs (exp) = words[1] | (words[0] << 16);
  4824.     }
  4825.       else if (ok != 0)
  4826.     {
  4827.       seg (exp) = absolute_section;
  4828.       op (exp) = O_constant;
  4829.       adds (exp) = 0;
  4830.       subs (exp) = 0;
  4831.       offs (exp) = (ok == 10) ? 1 : 0;
  4832.       as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp->e_beg, offs (exp));
  4833.     }
  4834.     }
  4835.   else
  4836.     {
  4837.       if (ok >= 10 && ok <= 70)
  4838.     {
  4839.       seg (exp) = absolute_section;
  4840.       op (exp) = O_constant;
  4841.       adds (exp) = 0;
  4842.       subs (exp) = 0;
  4843.       offs (exp) = (ok == 10) ? 1 : 0;
  4844.       as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp->e_beg, offs (exp));
  4845.     }
  4846.     }
  4847.  
  4848.   if (input_line_pointer != exp->e_end + 1)
  4849.     as_bad ("Ignoring junk after expression");
  4850.   exp->e_end[1] = c_save;
  4851.   input_line_pointer = save_in;
  4852.   if (exp->e_siz)
  4853.     {
  4854.       switch (exp->e_siz)
  4855.     {
  4856.     case 1:
  4857.       if (!isbyte (offs (exp)))
  4858.         as_warn ("expression doesn't fit in BYTE");
  4859.       break;
  4860.     case 2:
  4861.       if (!isword (offs (exp)))
  4862.         as_warn ("expression doesn't fit in WORD");
  4863.       break;
  4864.     }
  4865.     }
  4866.   return offs (exp);
  4867. #endif
  4868. }
  4869.  
  4870. /* These are the back-ends for the various machine dependent pseudo-ops.  */
  4871. void demand_empty_rest_of_line ();    /* Hate those extra verbose names */
  4872.  
  4873. static void
  4874. s_data1 (ignore)
  4875.      int ignore;
  4876. {
  4877.   subseg_set (data_section, 1);
  4878.   demand_empty_rest_of_line ();
  4879. }
  4880.  
  4881. static void
  4882. s_data2 (ignore)
  4883.      int ignore;
  4884. {
  4885.   subseg_set (data_section, 2);
  4886.   demand_empty_rest_of_line ();
  4887. }
  4888.  
  4889. static void
  4890. s_bss (ignore)
  4891.      int ignore;
  4892. {
  4893.   /* We don't support putting frags in the BSS segment, we fake it
  4894.      by marking in_bss, then looking at s_skip for clues.  */
  4895.  
  4896.   subseg_set (bss_section, 0);
  4897.   demand_empty_rest_of_line ();
  4898. }
  4899.  
  4900. static void
  4901. s_even (ignore)
  4902.      int ignore;
  4903. {
  4904.   register int temp;
  4905.   register long temp_fill;
  4906.  
  4907.   temp = 1;            /* JF should be 2? */
  4908.   temp_fill = get_absolute_expression ();
  4909.   if (!need_pass_2)        /* Never make frag if expect extra pass. */
  4910.     frag_align (temp, (int) temp_fill);
  4911.   demand_empty_rest_of_line ();
  4912. }
  4913.  
  4914. static void
  4915. s_proc (ignore)
  4916.      int ignore;
  4917. {
  4918.   demand_empty_rest_of_line ();
  4919. }
  4920.  
  4921. /* s_space is defined in read.c .skip is simply an alias to it. */
  4922.  
  4923.  
  4924. /*
  4925.  * md_parse_option
  4926.  *    Invocation line includes a switch not recognized by the base assembler.
  4927.  *    See if it's a processor-specific option.  These are:
  4928.  *
  4929.  *    -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
  4930.  *    -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
  4931.  *        Select the architecture.  Instructions or features not
  4932.  *        supported by the selected architecture cause fatal
  4933.  *        errors.  More than one may be specified.  The default is
  4934.  *        -m68020 -m68851 -m68881.  Note that -m68008 is a synonym
  4935.  *        for -m68000, and -m68882 is a synonym for -m68881.
  4936.  *    -[A]m[c]no-68851, -[A]m[c]no-68881
  4937.  *        Don't accept 688?1 instructions.  (The "c" is kind of silly,
  4938.  *        so don't use or document it, but that's the way the parsing
  4939.  *        works).
  4940.  *
  4941.  *    -pic    Indicates PIC.
  4942.  *    -k    Indicates PIC.  (Sun 3 only.)
  4943.  *
  4944.  * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
  4945.  * (e.g. m68020) also requests that float instructions be included.  This
  4946.  * is the default setup, mostly to avoid hassling users.  A better
  4947.  * rearrangement of this structure would be to add an option to DENY
  4948.  * floating point opcodes, for people who want to really know there's none
  4949.  * of that funny floaty stuff going on.  FIXME-later.
  4950.  */
  4951. #ifndef MAYBE_FLOAT_TOO
  4952. #define    MAYBE_FLOAT_TOO    /* m68881 */ 0    /* this is handled later */
  4953. #endif
  4954.  
  4955. CONST char *md_shortopts = "lSA:m:k";
  4956. struct option md_longopts[] = {
  4957. #define OPTION_PIC (OPTION_MD_BASE)
  4958.   {"pic", no_argument, NULL, OPTION_PIC},
  4959. #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
  4960.   {"register-prefix-optional", no_argument, NULL,
  4961.      OPTION_REGISTER_PREFIX_OPTIONAL},
  4962.   {NULL, no_argument, NULL, 0}
  4963. };
  4964. size_t md_longopts_size = sizeof(md_longopts);
  4965.  
  4966. int
  4967. md_parse_option (c, arg)
  4968.      int c;
  4969.      char *arg;
  4970. {
  4971.   switch (c)
  4972.     {
  4973.     case 'l':            /* -l means keep external to 2 bit offset
  4974.                    rather than 16 bit one */
  4975.       flag_short_refs = 1;
  4976.       break;
  4977.  
  4978.     case 'S':            /* -S means that jbsr's always turn into
  4979.                    jsr's.  */
  4980.       flag_long_jumps = 1;
  4981.       break;
  4982.  
  4983.     case 'A':
  4984.       if (*arg == 'm')
  4985.      arg++;
  4986.       /* intentional fall-through */
  4987.     case 'm':
  4988.       if (*arg == 'c')
  4989.      arg++;
  4990.  
  4991.       if (!strcmp (arg, "68000")
  4992.       || !strcmp (arg, "68008")
  4993.       || !strcmp (arg, "68302"))
  4994.     {
  4995.       current_architecture &=~ m68000up;
  4996.       current_architecture |= m68000;
  4997.     }
  4998.       else if (!strcmp (arg, "68010"))
  4999.     {
  5000.       current_architecture &=~ m68000up;
  5001.       current_architecture |= m68010;
  5002.     }
  5003.       else if (!strcmp (arg, "68020"))
  5004.     {
  5005.       current_architecture &=~ m68000up;
  5006.       current_architecture |= m68020 | MAYBE_FLOAT_TOO;
  5007.     }
  5008.       else if (!strcmp (arg, "68030"))
  5009.     {
  5010.       current_architecture &=~ m68000up;
  5011.       current_architecture |= m68030 | MAYBE_FLOAT_TOO;
  5012.     }
  5013.       else if (!strcmp (arg, "68040"))
  5014.     {
  5015.       current_architecture &=~ m68000up;
  5016.       current_architecture |= m68040 | MAYBE_FLOAT_TOO;
  5017.     }
  5018.       else if (!strcmp (arg, "68060"))
  5019.     {
  5020.       current_architecture &=~ m68000up;
  5021.       current_architecture |= m68060 | MAYBE_FLOAT_TOO;
  5022.     }
  5023. #ifndef NO_68881
  5024.       else if (!strcmp (arg, "68881"))
  5025.     {
  5026.       current_architecture |= m68881;
  5027.       no_68881 = 0;
  5028.     }
  5029.       else if (!strcmp (arg, "68882"))
  5030.     {
  5031.       current_architecture |= m68882;
  5032.       no_68881 = 0;
  5033.     }
  5034. #endif /* NO_68881 */
  5035.       /* Even if we aren't configured to support the processor,
  5036.      it should still be possible to assert that the user
  5037.      doesn't have it...  */
  5038.       else if (!strcmp (arg, "no-68881")
  5039.            || !strcmp (arg, "no-68882"))
  5040.     {
  5041.       no_68881 = 1;
  5042.     }
  5043. #ifndef NO_68851
  5044.       else if (!strcmp (arg, "68851"))
  5045.     {
  5046.       current_architecture |= m68851;
  5047.       no_68851 = 0;
  5048.     }
  5049. #endif /* NO_68851 */
  5050.       else if (!strcmp (arg, "no-68851"))
  5051.     {
  5052.       no_68851 = 1;
  5053.     }
  5054.       else if (!strcmp (arg, "pu32") /* "cpu32" minus 'c' */
  5055.            || !strcmp (arg, "68331")
  5056.            || !strcmp (arg, "68332")
  5057.            || !strcmp (arg, "68333")
  5058.            || !strcmp (arg, "68340"))
  5059.     {
  5060.       current_architecture &=~ m68000up;
  5061.       current_architecture |= cpu32;
  5062.     }
  5063.       else
  5064.     {
  5065.       as_bad ("invalid architecture %s", arg);
  5066.       return 0;
  5067.     }
  5068.       break;
  5069.  
  5070.     case OPTION_PIC:
  5071.     case 'k':
  5072.       flag_want_pic = 1;
  5073.       break;            /* -pic, Position Independent Code */
  5074.  
  5075.     case OPTION_REGISTER_PREFIX_OPTIONAL:
  5076.       flag_reg_prefix_optional = 1;
  5077.       break;
  5078.  
  5079.     default:
  5080.       return 0;
  5081.     }
  5082.  
  5083.   return 1;
  5084. }
  5085.  
  5086. void
  5087. md_show_usage (stream)
  5088.      FILE *stream;
  5089. {
  5090.   fprintf(stream, "\
  5091. 680X0 options:\n\
  5092. -l            use 1 word for refs to undefined symbols [default 2]\n\
  5093. -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040\n\
  5094.  | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -mcpu32\n\
  5095.             specify variant of 680X0 architecture [default 68020]\n\
  5096. -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
  5097.             target has/lacks floating-point coprocessor\n\
  5098.             [default yes for 68020, 68030, and cpu32]\n\
  5099. -m68851 | -mno-68851\n\
  5100.             target has/lacks memory-management unit coprocessor\n\
  5101.             [default yes for 68020 and up]\n\
  5102. -pic, -k        generate position independent code\n\
  5103. -S            turn jbsr into jsr\n\
  5104. --register-prefix-optional\n\
  5105.             recognize register names without prefix character\n");
  5106. }
  5107.  
  5108. #ifdef TEST2
  5109.  
  5110. /* TEST2:  Test md_assemble() */
  5111. /* Warning, this routine probably doesn't work anymore */
  5112.  
  5113. main ()
  5114. {
  5115.   struct m68k_it the_ins;
  5116.   char buf[120];
  5117.   char *cp;
  5118.   int n;
  5119.  
  5120.   m68k_ip_begin ();
  5121.   for (;;)
  5122.     {
  5123.       if (!gets (buf) || !*buf)
  5124.     break;
  5125.       if (buf[0] == '|' || buf[1] == '.')
  5126.     continue;
  5127.       for (cp = buf; *cp; cp++)
  5128.     if (*cp == '\t')
  5129.       *cp = ' ';
  5130.       if (is_label (buf))
  5131.     continue;
  5132.       memset (&the_ins, '\0', sizeof (the_ins));
  5133.       m68k_ip (&the_ins, buf);
  5134.       if (the_ins.error)
  5135.     {
  5136.       printf ("Error %s in %s\n", the_ins.error, buf);
  5137.     }
  5138.       else
  5139.     {
  5140.       printf ("Opcode(%d.%s): ", the_ins.numo, the_ins.args);
  5141.       for (n = 0; n < the_ins.numo; n++)
  5142.         printf (" 0x%x", the_ins.opcode[n] & 0xffff);
  5143.       printf ("    ");
  5144.       print_the_insn (&the_ins.opcode[0], stdout);
  5145.       (void) putchar ('\n');
  5146.     }
  5147.       for (n = 0; n < strlen (the_ins.args) / 2; n++)
  5148.     {
  5149.       if (the_ins.operands[n].error)
  5150.         {
  5151.           printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
  5152.           continue;
  5153.         }
  5154.       printf ("mode %d, reg %d, ", the_ins.operands[n].mode, the_ins.operands[n].reg);
  5155.       if (the_ins.operands[n].b_const)
  5156.         printf ("Constant: '%.*s', ", 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const, the_ins.operands[n].b_const);
  5157.       printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg, the_ins.operands[n].isiz, the_ins.operands[n].imul);
  5158.       if (the_ins.operands[n].b_iadd)
  5159.         printf ("Iadd: '%.*s',", 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd, the_ins.operands[n].b_iadd);
  5160.       (void) putchar ('\n');
  5161.     }
  5162.     }
  5163.   m68k_ip_end ();
  5164.   return 0;
  5165. }
  5166.  
  5167. is_label (str)
  5168.      char *str;
  5169. {
  5170.   while (*str == ' ')
  5171.     str++;
  5172.   while (*str && *str != ' ')
  5173.     str++;
  5174.   if (str[-1] == ':' || str[1] == '=')
  5175.     return 1;
  5176.   return 0;
  5177. }
  5178.  
  5179. #endif
  5180.  
  5181. /* Possible states for relaxation:
  5182.  
  5183.    0 0    branch offset    byte    (bra, etc)
  5184.    0 1            word
  5185.    0 2            long
  5186.  
  5187.    1 0    indexed offsets    byte    a0@(32,d4:w:1) etc
  5188.    1 1            word
  5189.    1 2            long
  5190.  
  5191.    2 0    two-offset index word-word a0@(32,d4)@(45) etc
  5192.    2 1            word-long
  5193.    2 2            long-word
  5194.    2 3            long-long
  5195.  
  5196.    */
  5197.  
  5198. /* We have no need to default values of symbols.  */
  5199.  
  5200. /* ARGSUSED */
  5201. symbolS *
  5202. md_undefined_symbol (name)
  5203.      char *name;
  5204. {
  5205.   return 0;
  5206. }
  5207.  
  5208. /* Parse an operand that is machine-specific.
  5209.    We just return without modifying the expression if we have nothing
  5210.    to do.  */
  5211.  
  5212. /* ARGSUSED */
  5213. void
  5214. md_operand (expressionP)
  5215.      expressionS *expressionP;
  5216. {
  5217. }
  5218.  
  5219. /* Round up a section size to the appropriate boundary.  */
  5220. valueT
  5221. md_section_align (segment, size)
  5222.      segT segment;
  5223.      valueT size;
  5224. {
  5225.   return size;            /* Byte alignment is fine */
  5226. }
  5227.  
  5228. /* Exactly what point is a PC-relative offset relative TO?
  5229.    On the 68k, they're relative to the address of the offset, plus
  5230.    its size. (??? Is this right?  FIXME-SOON!) */
  5231. long
  5232. md_pcrel_from (fixP)
  5233.      fixS *fixP;
  5234. {
  5235.   return (fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address);
  5236. }
  5237.  
  5238. #ifndef BFD_ASSEMBLER
  5239. /*ARGSUSED*/
  5240. void
  5241. tc_coff_symbol_emit_hook (ignore)
  5242.      symbolS *ignore;
  5243. {
  5244. }
  5245.  
  5246. int
  5247. tc_coff_sizemachdep (frag)
  5248.      fragS *frag;
  5249. {
  5250.   switch (frag->fr_subtype & 0x3)
  5251.     {
  5252.     case BYTE:
  5253.       return 1;
  5254.     case SHORT:
  5255.       return 2;
  5256.     case LONG:
  5257.       return 4;
  5258.     default:
  5259.       abort ();
  5260.     }
  5261. }
  5262. #endif
  5263.  
  5264. /* end of tc-m68k.c */
  5265.